Skip to content

Commit c3edf13

Browse files
Googlercopybara-github
Googler
authored andcommitted
Ignore deletion failure of temporary directories due to java.nio.DirectoryNotEmptyException.
PiperOrigin-RevId: 364909970
1 parent 0b51d43 commit c3edf13

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/tools/android/java/com/google/devtools/build/android/ScopedTemporaryDirectory.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import java.io.Closeable;
2121
import java.io.IOException;
22+
import java.nio.file.DirectoryNotEmptyException;
2223
import java.nio.file.FileStore;
2324
import java.nio.file.FileVisitResult;
2425
import java.nio.file.Files;
@@ -30,8 +31,9 @@
3031
import java.util.EnumSet;
3132

3233
/**
33-
* Creates a temporary directory that will be deleted once a scope closes. NOTE: If an error occurs
34-
* during deletion, it will just stop rather than try and continue.
34+
* Creates a temporary directory that will be deleted once a scope closes. NOTE: errors during
35+
* deletion are ignored, which can lead to inclomplete clean up of the temporary files. However, as
36+
* they are created in the temp location, the system should eventually clean them up.
3537
*/
3638
final class ScopedTemporaryDirectory extends SimpleFileVisitor<Path> implements Closeable {
3739

@@ -91,7 +93,11 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
9193

9294
@Override
9395
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
94-
Files.delete(dir);
96+
try {
97+
Files.delete(dir);
98+
} catch (DirectoryNotEmptyException e) {
99+
// Ignore.
100+
}
95101
return FileVisitResult.CONTINUE;
96102
}
97103

0 commit comments

Comments
 (0)