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:
Balázs Szücs
2026-02-06 13:12:38 -07:00
committed by GitHub
parent cd428c6fe3
commit f5326ce435
@@ -24,6 +24,7 @@ import org.springframework.transaction.support.TransactionTemplate;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
@AllArgsConstructor @AllArgsConstructor
@Service @Service
@@ -208,9 +209,15 @@ public class FileMoveService {
throw e; 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) { for (Path sourceParent : sourceParentsToCleanup) {
fileMoveHelper.deleteEmptyParentDirsUpToLibraryFolders(sourceParent, Set.of(libraryRoot)); fileMoveHelper.deleteEmptyParentDirsUpToLibraryFolders(sourceParent, libraryRoots);
} }
entityManager.clear(); entityManager.clear();
@@ -355,8 +362,15 @@ public class FileMoveService {
} }
// Clean up empty parent directories // 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) { for (Path sourceParent : sourceParentsToCleanup) {
fileMoveHelper.deleteEmptyParentDirsUpToLibraryFolders(sourceParent, Set.of(libraryRoot)); fileMoveHelper.deleteEmptyParentDirsUpToLibraryFolders(sourceParent, libraryRoots);
} }
if (isLibraryMonitoredWhenCalled) { if (isLibraryMonitoredWhenCalled) {