Skip to content

Commit

Permalink
Improve FileUtils.deleteRecursively diagnostics. (deephaven#5430)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpwright authored May 1, 2024
1 parent 3a34e5c commit ffad907
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions Base/src/main/java/io/deephaven/base/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import java.io.*;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -59,19 +61,23 @@ public static void cleanDirectory(File path) {
}

public static void deleteRecursively(File file) {
if (!file.exists()) {
if (!Files.exists(file.toPath(), LinkOption.NOFOLLOW_LINKS)) {
return;
}
if (file.isDirectory()) {
File f[] = file.listFiles();
final File[] files = file.listFiles();

if (f != null) {
for (File file1 : f) {
deleteRecursively(file1);
if (files != null) {
for (final File child : files) {
deleteRecursively(child);
}
}
}
Assert.assertion(file.delete(), "file.delete()", file.getAbsolutePath(), "file");
try {
Files.deleteIfExists(file.toPath());
} catch (IOException e) {
throw new UncheckedIOException("Could not delete file: " + file.getAbsolutePath(), e);
}
}

/**
Expand Down

0 comments on commit ffad907

Please sign in to comment.