forked from Qortal/qortal
Fixed bugs in safeDeleteEmptyParentDirectories()
This commit is contained in:
parent
b7ee00fb22
commit
97cdd53861
@ -169,16 +169,22 @@ public class FilesystemUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void safeDeleteEmptyParentDirectories(Path path) throws IOException {
|
public static void safeDeleteEmptyParentDirectories(Path path) throws IOException {
|
||||||
final Path absolutePath = path.toAbsolutePath();
|
final Path parentPath = path.toAbsolutePath().getParent();
|
||||||
if (!absolutePath.toFile().isDirectory()) {
|
if (!parentPath.toFile().isDirectory()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!FilesystemUtils.pathInsideDataOrTempPath(absolutePath)) {
|
if (!FilesystemUtils.pathInsideDataOrTempPath(parentPath)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Files.deleteIfExists(absolutePath);
|
try {
|
||||||
|
Files.deleteIfExists(parentPath);
|
||||||
|
|
||||||
FilesystemUtils.safeDeleteEmptyParentDirectories(absolutePath.getParent());
|
} catch (DirectoryNotEmptyException e) {
|
||||||
|
// We've reached the limits of what we can delete
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
FilesystemUtils.safeDeleteEmptyParentDirectories(parentPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean pathInsideDataOrTempPath(Path path) {
|
public static boolean pathInsideDataOrTempPath(Path path) {
|
||||||
|
Loading…
Reference in New Issue
Block a user