Continue deleting other files when some fail to delete in FileUtils#1103
Continue deleting other files when some fail to delete in FileUtils#1103torusrxxx wants to merge 4 commits intohyphanet:nextfrom
Conversation
…and use distinct temp file names in tests.
| import java.io.InputStream; | ||
| import java.io.OutputStream; | ||
|
|
||
| import java.io.*; |
There was a problem hiding this comment.
Please don't collapse imports into wildcard imports.
| try ( | ||
| FileOutputStream fos = new FileOutputStream("output.utf16") | ||
| ){ | ||
| new File("output.utf16").deleteOnExit(); |
There was a problem hiding this comment.
This and the below instances should really use a finally block instead of resorting to JVM shutdown hooks with deleteOnExit.
|
As a side note: really, these methods should be rewritten using None of that is introduced in this change, so feel free to not do anything about it in this PR. Also, "secure deleting" is becoming increasingly meaningless in the modern days of copy-on-write filesystems and SSD drives (which are essentially copy-on-write hardware) ... but that's for another day 😉 |
src/freenet/support/io/FileUtil.java
Outdated
| boolean success = true; | ||
| for(File subfile: wd.listFiles()) { | ||
| if(!removeAll(subfile)) return false; | ||
| if(!secureDeleteAll(subfile)){ |
There was a problem hiding this comment.
| if(!secureDeleteAll(subfile)){ | |
| success &= secureDeleteAll(subfile); |
src/freenet/support/io/FileUtil.java
Outdated
| boolean success = true; | ||
| for(File subfile: wd.listFiles()) { | ||
| if(!removeAll(subfile)) return false; | ||
| if(!removeAll(subfile)){ |
|
|
||
| @After | ||
| public void tearDown() { | ||
| FileUtil.removeAll(dir); |
There was a problem hiding this comment.
While that is certainly a possibility, JUnit offers a TemporaryDirectory rule that takes care of this automatically; can that be used, maybe?
There was a problem hiding this comment.
JUnit 5 does not support @Rule. I think we will need to migrate to JUnit 5 and therefore stop using @Rule.
There was a problem hiding this comment.
I don’t see a pressing reason to migrate to JUnit 5, JUnit 4 certainly seems to work fine, so @Rule it is — unless it’s more of a hassle than it’s worth (which can happen if lots of objects get constructed before the actual test method is running). 😁
There was a problem hiding this comment.
No, we still need to migrate to JUnit 5 simply because we will not be using JUnit 4 forever. The migration to vintage engine should start as soon as possible so that new tests don't need to migrate from JUnit 4 to JUnit 5.
There was a problem hiding this comment.
Uhm, we are still on Java 8, I’m pretty confident that a lot of time will pass until we actually need to migrate to JUnit 5. But even if we do, migrating a TemporaryFolder from a @Rule to a @TempDir is almost trivial.
|
|
||
| @Before | ||
| public void setUp() { | ||
| base = new File("tmp.encrypted-random-access-thing-test"); |
There was a problem hiding this comment.
If a member variable is only assigned once and doesn’t depend on anything else and its initialization does not throw an exception, please make the member variable final and assign it in the declaration.
|
@torusrxxx kindly stop adding to the scope of this PR - if you want to make other improvements, please use a different branch and file a separate PR. This serves two purposes:
The changes in |
| dir = new File("split-file-inserter-storage-test"); | ||
| dir.mkdir(); | ||
| tempFolder = new TemporaryFolder(); | ||
| tempFolder.create(); |
There was a problem hiding this comment.
I’m not sure we should use the method that is documented with “for testing purposes only. Do not use.”
This is exactly the situation I was referring to in my earlier comment about how TemporaryFolder can’t be used during constructor invocation.
|
It looks like part of this pull request will be superseded by #1107. I will have to reopen a new PR. |
Thank you for the info! And don’t worry: real life must take precedence, otherwise you have little chance to stay active on the long run. I just stumbled over an article that described that burnout is one of the prime reasons for FOSS devs to stop, so keeping the balance is vitally important. |
secureDeleteAllshould delete all files in a directory usingsecureDeleteAll.FileUtils.