Skip to content

Commit 5a114fe

Browse files
committed
Be careful in createTemporaryDirectory() when removing existing files
If File.exists() returns true, it might be a regular file being in the way, after all... Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent b164a97 commit 5a114fe

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/main/java/org/scijava/test/TestUtils.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@ public static File createTemporaryDirectory(final String prefix,
119119
}
120120

121121
final File file = new File(baseDirectory, prefix + suffix);
122-
if (file.exists()) FileUtils.deleteRecursively(file);
122+
if (file.isDirectory()) FileUtils.deleteRecursively(file);
123+
else if (file.exists() && !file.delete()) {
124+
throw new IOException("Could not remove " + file);
125+
}
123126
if (!file.mkdir()) throw new IOException("Could not make directory " + file);
124127
return file;
125128
}

0 commit comments

Comments
 (0)