mirror of
https://github.com/adityachandelgit/BookLore.git
synced 2026-02-18 03:07:40 +01:00
fix(file-move): update empty directory cleanup to handle multiple library paths (#2634)
Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
This commit is contained in:
@@ -24,6 +24,7 @@ import org.springframework.transaction.support.TransactionTemplate;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@AllArgsConstructor
|
||||
@Service
|
||||
@@ -208,9 +209,15 @@ public class FileMoveService {
|
||||
throw e;
|
||||
}
|
||||
|
||||
Path libraryRoot = Paths.get(libraryPathEntity.getPath()).toAbsolutePath().normalize();
|
||||
Set<Path> libraryRoots = targetLibrary.getLibraryPaths().stream()
|
||||
.map(LibraryPathEntity::getPath)
|
||||
.map(Paths::get)
|
||||
.map(Path::toAbsolutePath)
|
||||
.map(Path::normalize)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
for (Path sourceParent : sourceParentsToCleanup) {
|
||||
fileMoveHelper.deleteEmptyParentDirsUpToLibraryFolders(sourceParent, Set.of(libraryRoot));
|
||||
fileMoveHelper.deleteEmptyParentDirsUpToLibraryFolders(sourceParent, libraryRoots);
|
||||
}
|
||||
|
||||
entityManager.clear();
|
||||
@@ -355,8 +362,15 @@ public class FileMoveService {
|
||||
}
|
||||
|
||||
// Clean up empty parent directories
|
||||
Set<Path> libraryRoots = bookWithFiles.getLibraryPath().getLibrary().getLibraryPaths().stream()
|
||||
.map(LibraryPathEntity::getPath)
|
||||
.map(Paths::get)
|
||||
.map(Path::toAbsolutePath)
|
||||
.map(Path::normalize)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
for (Path sourceParent : sourceParentsToCleanup) {
|
||||
fileMoveHelper.deleteEmptyParentDirsUpToLibraryFolders(sourceParent, Set.of(libraryRoot));
|
||||
fileMoveHelper.deleteEmptyParentDirsUpToLibraryFolders(sourceParent, libraryRoots);
|
||||
}
|
||||
|
||||
if (isLibraryMonitoredWhenCalled) {
|
||||
|
||||
Reference in New Issue
Block a user