fix(file-move): clean up emptied source folders after sidecar move (#822)

This commit is contained in:
Zach
2026-04-24 12:23:25 +02:00
committed by GitHub
parent e4e4c9196a
commit cb12ff1b7f
3 changed files with 36 additions and 10 deletions
@@ -236,16 +236,16 @@ public class FileMoveService {
// Also protect the source library root so cleanup doesn't traverse above it
libraryRoots.add(Paths.get(bookEntity.getLibraryPath().getPath()).toAbsolutePath().normalize());
for (Path sourceParent : sourceParentsToCleanup) {
fileMoveHelper.deleteEmptyParentDirsUpToLibraryFolders(sourceParent, libraryRoots);
}
try {
sidecarMetadataWriter.moveSidecarFiles(currentPrimaryFilePath, newFilePath);
} catch (Exception e) {
log.warn("Failed to move sidecar files for book ID {}: {}", bookId, e.getMessage());
}
for (Path sourceParent : sourceParentsToCleanup) {
fileMoveHelper.deleteEmptyParentDirsUpToLibraryFolders(sourceParent, libraryRoots);
}
entityManager.clear();
BookEntity fresh = bookRepository.findByIdWithBookFiles(bookId).orElseThrow();
@@ -417,16 +417,16 @@ public class FileMoveService {
// Also protect the source library root so cleanup doesn't traverse above it
libraryRoots.add(Paths.get(bookWithFiles.getLibraryPath().getPath()).toAbsolutePath().normalize());
for (Path sourceParent : sourceParentsToCleanup) {
fileMoveHelper.deleteEmptyParentDirsUpToLibraryFolders(sourceParent, libraryRoots);
}
try {
sidecarMetadataWriter.moveSidecarFiles(currentPrimaryFilePath, expectedPrimaryFilePath);
} catch (Exception e) {
log.warn("Failed to move sidecar files for book ID {}: {}", bookEntity.getId(), e.getMessage());
}
for (Path sourceParent : sourceParentsToCleanup) {
fileMoveHelper.deleteEmptyParentDirsUpToLibraryFolders(sourceParent, libraryRoots);
}
if (isLibraryMonitoredWhenCalled) {
// Ensure any file system events from the move and cleanup are drained/ignored while we are still unregistered
sleep(EVENT_DRAIN_TIMEOUT_MS);