Skip to content

Commit

Permalink
Improve FileUtils.deleteRecursively diagnostics. (#5430)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpwright authored and stanbrub committed May 17, 2024
1 parent d0ddd90 commit 671a9f6
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 @@ -9,6 +9,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 @@ -50,19 +52,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 671a9f6

Please sign in to comment.