ArbitraryDataFile.cleanupFilesystem() now uses generic FilesystemUtils.safeDeleteEmptyParentDirectories() code.

This commit is contained in:
CalDescent 2021-12-15 12:15:58 +00:00
parent a4e82c79cc
commit d6479c1390

View File

@ -401,26 +401,12 @@ public class ArbitraryDataFile {
return fileDeleted || metadataDeleted || chunksDeleted; return fileDeleted || metadataDeleted || chunksDeleted;
} }
protected void cleanupFilesystem() { protected void cleanupFilesystem() throws IOException {
// It is essential that use a separate path reference in this method // It is essential that use a separate path reference in this method
// as we don't want to modify this.filePath // as we don't want to modify this.filePath
Path path = this.filePath; Path path = this.filePath;
// Iterate through two levels of parent directories, and delete if empty FilesystemUtils.safeDeleteEmptyParentDirectories(path);
for (int i=0; i<2; i++) {
Path directory = path.getParent().toAbsolutePath();
try (Stream<Path> files = Files.list(directory)) {
final long count = files.count();
if (count == 0) {
if (FilesystemUtils.pathInsideDataOrTempPath(directory)) {
Files.delete(directory);
}
}
} catch (IOException e) {
LOGGER.warn("Unable to count files in directory", e);
}
path = directory;
}
} }
public byte[] getBytes() { public byte[] getBytes() {