From f5326ce4352cb8c2533ab2ed2bc4fa6aae87f490 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Sz=C3=BCcs?= <127139797+balazs-szucs@users.noreply.github.com> Date: Fri, 6 Feb 2026 21:12:38 +0100 Subject: [PATCH] fix(file-move): update empty directory cleanup to handle multiple library paths (#2634) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Balázs Szücs --- .../service/file/FileMoveService.java | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/booklore-api/src/main/java/org/booklore/service/file/FileMoveService.java b/booklore-api/src/main/java/org/booklore/service/file/FileMoveService.java index e782903be..95486ad32 100644 --- a/booklore-api/src/main/java/org/booklore/service/file/FileMoveService.java +++ b/booklore-api/src/main/java/org/booklore/service/file/FileMoveService.java @@ -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 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 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) {