Skip to content

Commit 28cdca3

Browse files
committed
Update FileUtils.java
1 parent c4732af commit 28cdca3

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

src/main/java/io/github/intisy/gradle/github/utils/FileUtils.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,16 @@ public static void copyDirectory(Path sourceDir, Path destDir) throws IOExceptio
4747
* @throws IOException if an I/O error occurs
4848
*/
4949
public static void deleteDirectory(Path dir) throws IOException {
50-
if (!Files.exists(dir) || !Files.isDirectory(dir)) {
51-
throw new IllegalArgumentException("Directory does not exist or is not a directory.");
50+
if (Files.exists(dir) && Files.isDirectory(dir)) {
51+
Files.walk(dir)
52+
.sorted((path1, path2) -> path2.compareTo(path1)) // Sort in reverse order to delete files before directories
53+
.forEach(path -> {
54+
try {
55+
Files.delete(path);
56+
} catch (IOException e) {
57+
throw new RuntimeException("Error deleting directory", e);
58+
}
59+
});
5260
}
53-
54-
Files.walk(dir)
55-
.sorted((path1, path2) -> path2.compareTo(path1)) // Sort in reverse order to delete files before directories
56-
.forEach(path -> {
57-
try {
58-
Files.delete(path);
59-
} catch (IOException e) {
60-
throw new RuntimeException("Error deleting directory", e);
61-
}
62-
});
6361
}
6462
}

0 commit comments

Comments
 (0)