Skip to content

Commit d3bcaa6

Browse files
committed
Better test clean up
- Attempt to resolve "random" build failures in GH CI on macOS - Local build OK
1 parent a58965d commit d3bcaa6

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
import java.io.OutputStream;
2424
import java.nio.charset.StandardCharsets;
25-
import java.nio.file.Files;
2625
import java.nio.file.Path;
2726

2827
import org.apache.commons.io.file.PathUtils;
@@ -82,11 +81,21 @@ private boolean isWindows() {
8281
public void tearDown() throws Exception {
8382
final FileObject scratchFolder = getWriteFolder();
8483
final FileObject file = scratchFolder.resolveFile(FILE_NAME);
85-
file.setWritable(true, true);
84+
try {
85+
file.setReadable(true, false);
86+
} catch (final FileSystemException e) {
87+
e.printStackTrace();
88+
}
89+
try {
90+
file.setWritable(true, false);
91+
} catch (final FileSystemException e) {
92+
e.printStackTrace();
93+
}
8694
if (!file.delete()) {
8795
final Path path = file.getPath();
88-
if (getFileSystem() instanceof LocalFileSystem) {
89-
PathUtils.deleteFile(path, StandardDeleteOption.OVERRIDE_READ_ONLY);
96+
if ((getFileSystem() instanceof LocalFileSystem)
97+
&& (PathUtils.deleteFile(path, StandardDeleteOption.OVERRIDE_READ_ONLY).getFileCounter().get() == 0)) {
98+
System.err.println("Test tear down can't delete " + path);
9099
}
91100
}
92101
}

0 commit comments

Comments
 (0)