Skip to content

Commit

Permalink
Ignore deletion failure of temporary directories due to java.nio.Dire…
Browse files Browse the repository at this point in the history
…ctoryNotEmptyException.

PiperOrigin-RevId: 364909970
  • Loading branch information
Googler authored and copybara-github committed Mar 24, 2021
1 parent 0b51d43 commit c3edf13
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.io.Closeable;
import java.io.IOException;
import java.nio.file.DirectoryNotEmptyException;
import java.nio.file.FileStore;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
Expand All @@ -30,8 +31,9 @@
import java.util.EnumSet;

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

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

@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
Files.delete(dir);
try {
Files.delete(dir);
} catch (DirectoryNotEmptyException e) {
// Ignore.
}
return FileVisitResult.CONTINUE;
}

Expand Down

0 comments on commit c3edf13

Please sign in to comment.