fix(file-move): clean up emptied source folders after sidecar move (#822)
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user