Repository navigation
fix: never let post-import cleanup delete library content - #353
Merged
Merged
Conversation
Moves cleanupDownloadAfterOrganize and cleanupSourceAfterOrganize out of organize-files.processor.ts into organize-cleanup.ts unchanged, so the processor shrinks and the cleanup paths can be tested on their own. No behavior change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
After a manual import, "remove after processing" cleanup took the request's newest download history row regardless of where the job came from and recursively deleted the import folder. A folder picked from the media library, or the media root itself, was wiped. The opt-in source cleanup also unlinked the library files when source and target were the same folder, and an in-place re-import truncated cover.jpg to 0 bytes by copying it onto itself. The ebook branch removed the whole import folder, which can also hold the audiobook. - Download cleanup now runs only for downloads RMAB completed: the job must carry its downloadHistoryId (monitor, retry, direct download and request retry pass it; manual and bulk import never do), the row must be completed and its stored download path must equal the job path. Missing indexer protocols fall back to the client's protocol. - retry-failed-imports stores a client-reported (mapped) path on the row before queueing so retried downloads stay eligible; a failed write only skips cleanup. - New assertSafeToDelete guard used by both cleanups refuses the organize target (equal, containing or inside), any configured root (media, download, per-client custom and mapped paths, bookdrop), and anything in the media dir unless it sits in a download root nested inside it. Paths are realpath-canonicalized and compared by dev+inode as well. - Ebook source cleanup removes only the imported ebook file. - copyFile is a no-op when source and destination are the same file, and the organizer skips audio and cover art that are already in place. - media_dir resolution is shared between the organizer and cleanup. Fixes #242 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The ebook organizer no longer deletes its source. Direct HTTP download files are removed afterwards by cleanupDirectDownloadSource, which uses the same provenance check as download cleanup (the job's own downloadHistoryId row, completed, stored path == job path) and the delete guard. - The ebook branch decides seeding vs direct from the job's own download row instead of the request's newest row. - Ebook source cleanup removes the file the organizer actually read (the original EPUB only when the Kindle fix produced a temp copy), so a folder with several EPUBs loses only the imported one. - Docs: note that organize jobs queued before upgrading skip download cleanup once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nual - A manual or bulk import (no downloadHistoryId) that fails is marked failed with a message to re-run it, instead of going to awaiting_import, where the retry job would re-queue the request's last client download with its cleanup. - Whole-folder source cleanup never removes a folder inside the media library; with selectedFiles only those files are removed. - The empty-parent sweep is bounded by the nearest configured root and never removes a root (download_dir, client custom or mapped paths, media_dir, bookdrop) or climbs from a download root into the library. - Cleanup aborts when the download client list cannot be read. - Deletes act on the canonical path the guard checked; a symlink candidate is removed as a link. - Windows drive roots normalize to "C:/" instead of "C:." so the current directory is never mistaken for an ancestor. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Manual and bulk imports are told apart from download jobs exactly (no downloadHistoryId and a boolean cleanupSource). When one fails, the request is marked failed and a success:false result is returned, so queue retries no longer re-run it or send repeated notifications. Download jobs queued before this change keep their import retry. - The failure message reads "Import from <path> did not complete: ...", and the notification text leaves the server path out. - The delete guard reads download_dir and download_clients straight from the database and parses without a fallback; any error aborts the delete. - Trailing separators are stripped before the symlink check. - Guard root collection, guarded delete and the parent sweep move to organize-cleanup-guard.ts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #242
What changed
Why
#242 (thanks @azerbe): after a manual import from the library, the "remove after processing" cleanup deleted the imported folder. Importing from the media root removed the whole library.
Evidence
End-to-end on disposable Docker stacks (generated audio, fake indexer and download clients, real Audiobookshelf), with three layouts: usenet with a second mount of the media volume, torrent, and usenet with remote path mapping.
99fabde, 11 of the delete cases lose library files, including the media root case.The per-case table is in the gist.
Full logs: https://gist.github.com/kikootwo/f76c76ece312b6ae0bec8e1eaa5a4337
Checks
dockerfile.unified): PASSRisk and rollback
Cleanup now declines in more situations than before. When it declines, the files stay where they are and the log says why. Organize jobs that were already queued when you upgrade skip download cleanup once (their files stay, and client history isn't archived). Reverting this PR restores the previous cleanup.
🤖 Generated with Claude Code