Skip to content

Commit d9be55f

Browse files
committed
Bullet proofing of test tear down
1 parent 1e4f5c0 commit d9be55f

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

commons-vfs2/src/test/java/org/apache/commons/vfs2/PermissionsTests.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import static org.junit.jupiter.api.Assertions.assertNotNull;
2121
import static org.junit.jupiter.api.Assertions.assertTrue;
2222

23+
import java.io.File;
2324
import java.io.OutputStream;
2425
import java.nio.charset.StandardCharsets;
2526
import java.nio.file.Path;
@@ -83,19 +84,27 @@ public void tearDown() throws Exception {
8384
final FileObject file = scratchFolder.resolveFile(FILE_NAME);
8485
try {
8586
file.setReadable(true, false);
87+
file.getParent().setReadable(true, false);
8688
} catch (final FileSystemException e) {
8789
e.printStackTrace();
8890
}
8991
try {
9092
file.setWritable(true, false);
93+
file.getParent().setWritable(true, false);
9194
} catch (final FileSystemException e) {
9295
e.printStackTrace();
9396
}
9497
if (!file.delete()) {
9598
final Path path = file.getPath();
9699
if ((getFileSystem() instanceof LocalFileSystem)
97100
&& (PathUtils.deleteFile(path, StandardDeleteOption.OVERRIDE_READ_ONLY).getFileCounter().get() == 0)) {
98-
System.err.println("Test tear down can't delete " + path);
101+
File f = path.toFile();
102+
if (!f.delete()) {
103+
f.deleteOnExit();
104+
}
105+
if (f.exists()) {
106+
System.err.println("Test tear down can't delete " + path);
107+
}
99108
}
100109
}
101110
}

0 commit comments

Comments
 (0)