Repository navigation
fix(scanner): remove a deleted movie or series folder on the scan that follows - #3093
Conversation
A subtree scan scoped to a movie or series folder that was deleted, while its parent directory is still there, now walks the folder as empty instead of recording an unreadable path. Its files are marked missing and the title leaves the library, as a full library scan already did, and no partial_walk warning is raised. A folder whose parent is gone too, one below a dangling symlink, and non-ENOENT errors stay protected.
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
|
Evidence is missing for two visible effects:
The Evidence section says the captures are being uploaded but provides no attachments or evidence URL. Suggested fix: publish the captures and replace “link follows” with the evidence URL. Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness. Posted via Macroscope — Visible change evidence |
| if scopeRootVanished(cleanRoot, libraryRoots) { | ||
| slog.InfoContext(ctx, "scanner: scope no longer exists under its library root; reconciling it as empty", "component", "scanner", "path", cleanRoot) | ||
| continue | ||
| } | ||
| rules, ignored, err := scanRootIgnoreRules(cleanRoot, libraryRoots) |
There was a problem hiding this comment.
Walk-failure protection in internal/scanner/scanner.go fails because the vanished-scope shortcut bypasses the ancestor readability check: an execute-only parent lets Lstat return ENOENT and Stat confirm a directory even though scanRootIgnoreRules would fail its ReadDir, allowing scanPaths to mark cataloged files missing and remove their library memberships under an unreadable nested ancestor. Move the shortcut after scanRootIgnoreRules succeeds and its ignored check.
Prompt for LLM
File internal/scanner/scanner.go:
Line 741 to 745:
Walk-failure protection in internal/scanner/scanner.go fails because the vanished-scope shortcut bypasses the ancestor readability check: an execute-only parent lets Lstat return ENOENT and Stat confirm a directory even though scanRootIgnoreRules would fail its ReadDir, allowing scanPaths to mark cataloged files missing and remove their library memberships under an unreadable nested ancestor. Move the shortcut after scanRootIgnoreRules succeeds and its ignored check.
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
There was a problem hiding this comment.
Not changing this. With an execute-only parent, lookup through it still works: Lstat on a folder that exists there succeeds, so scopeRootVanished returns false and the walk takes the existing path (the ignore-ancestor read fails and the scope stays protected). ENOENT comes back only when the folder is really gone, and then nothing can be hidden under it. The unreadable parent only stops the scan from reading ignore files, and an ignored scope and a missing one both end up with no files under them. A parent without search permission makes Lstat return EACCES, which stays a walk failure.
There was a problem hiding this comment.
You're right—the suggestion conflated directory readability with path lookup permission.
With search (x) permission on the parent:
- An existing scope remains discoverable by
Lstat, so the shortcut does not apply. The existing ignore-ancestor check can fail and protect the scope. - A genuinely missing scope produces
ENOENT. Given the parent-directory and dangling-symlink checks described, failure to read the parent's ignore files does not establish that files are hidden beneath that missing scope.
Without search permission, lookup returns EACCES, which does not qualify for the shortcut and remains protected.
Moving the shortcut after scanRootIgnoreRules would therefore preserve a missing scope because its parent's ignore files cannot be read—not fix the hidden-files scenario my comment claimed.
I retract the suggestion. The execute-only-parent case does not substantiate the reported bug or its critical severity.
| if _, err := os.Lstat(scope); !errors.Is(err, fs.ErrNotExist) { | ||
| return false | ||
| } | ||
| parent, err := os.Stat(filepath.Dir(scope)) |
There was a problem hiding this comment.
Incorrect parent-path handling in internal/scanner/scanner.go passes the encoded spelling directly to os.Stat, which can inspect the wrong directory or fail despite the actual parent's existence, making deletion reconciliation inconsistent with the filesystem. Decode filepath.Dir(scope) with fspath.Decode before passing it to os.Stat, and add the filesystem-path package import.
Also found in:
internal/scanner/scanner.go:776-776
Kody rule violation: Respect encoded filesystem paths at every Go boundary
parent, err := os.Stat(fspath.Decode(filepath.Dir(scope)))Prompt for LLM
File internal/scanner/scanner.go:
Line 779:
Incorrect parent-path handling in internal/scanner/scanner.go passes the encoded spelling directly to os.Stat, which can inspect the wrong directory or fail despite the actual parent's existence, making deletion reconciliation inconsistent with the filesystem. Decode filepath.Dir(scope) with fspath.Decode before passing it to os.Stat, and add the filesystem-path package import.
**Also found in:**
- `internal/scanner/scanner.go:776-776`
Suggested Code:
parent, err := os.Stat(fspath.Decode(filepath.Dir(scope)))
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
There was a problem hiding this comment.
Not applicable here: this repository has no fspath package, and the scanner passes walk roots and paths to os.Lstat, os.ReadDir and os.Stat as they are, as walkLogicalTree does just above. filepath.Dir(scope) is the same kind of path as scope.
There was a problem hiding this comment.
You're right—this suggestion is a false positive. I incorrectly assumed an encoded-path abstraction and a fspath package that this repository does not have.
filepath.Dir(scope) preserves the native filesystem-path representation used by scope and the surrounding scanner code. Passing it directly to os.Stat is consistent with that handling; no decoding or additional import is needed.
The suggested change should be disregarded.
|
The evidence was published right after this check ran, and the Evidence section now links it: desktop and mobile web captures of the Movies library page and Admin > Libraries, on |
|
Both cases named on the
Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed. Posted via Macroscope — v1 validation impact |
|
On the "searchable but unreadable parent" concern in CodeRabbit's merge-risk summary: it is the same point Kody raised, answered in #3093 (comment). With search permission on the parent, |
Problem
Related issue: #3060
Validation tasks: none
Deleting a single movie or series folder leaves the title in the library, and Admin > Libraries shows a "Partial scan" warning. It happens on any library with realtime monitoring, and when an Autoscan source reports the deletion. A full library scan of the same state removes the title, so the two scans disagree about one deletion. With this change, the scan that follows the deletion removes the title and raises no warning.
The monitor and Autoscan's directory fallback queue a subtree scan scoped to the deleted folder itself. The scanner's walk recorded that folder's
ENOENTas an unreadable path, and unreadable paths are protected from missing-file cleanup and set thepartial_walkwarning.Approach
A subtree scan now treats its own folder as empty, not unreadable, when the folder is gone (
ENOENT) and its parent is still a directory. The folder's files are marked missing and the title loses its library membership, as on a full library scan. The check is in the scanner's walk (scopeRootVanished), so every subtree caller gets it: the realtime monitor, Autoscan, the scan API and the admin split rescan. Changing the resolver to scope these scans to an existing parent instead would rescan a whole library root for one deleted folder.Lost-mount protection otherwise stays as it was:
ENOENT.The files still wait out
scanner.file_removal_gracein the trash, so a folder that comes back within the grace restores its title. Ebook and audiobook subtree scans use their own walks and are not changed; books are beta.This overlaps #3060. That issue asks that a series or movie deleted in Sonarr or Radarr leave the library, and also that a folder which vanished without arr's confirmation keep the lost-mount protection. This change departs from that second point: a vanished folder is protected only when its parent is gone too. Parsing
SeriesDelete/MovieDeleteand skipping the grace for arr deletions remain open in #3060.Validation
internal/scanner,internal/scantrigger,internal/librarymonitorandinternal/autoscanpass. The new Postgres test (a deleted movie folder) fails onmainand passes here, and is listed inscripts/ci/db-contracts.txt.make test-db-contractspasses against a disposable migrated database.go build,gofmt,go vet,make lint-changed,make lint-router-recovery,make verify-local-paths,make verify-size-ratchet,make verify-bidiandmake verify-case-collisionspass.make test-gopasses except twointernal/jellycompatDolby Vision tests (TestPlaybackInfoWithoutStripOrToneMapStillHasNoRoute,TestPlaybackInfoSkipsStripWhenRPUCannotBeStripped), which fail the same way onmainon the same machine.mainkept the title listed with thepartial_walkwarning; this branch removed it from the library with no warning.Evidence
Evidence: https://evidence.siloserver.org/r/silo-server/pr-3093/
The captures show the Movies library page and Admin > Libraries on desktop and mobile web, after the same folder deletion on
main(6de6d5e) and on this branch (469a521).Risks
A folder that disappears below a library root while its parent stays (for example, a mount that is not a configured library root and whose mountpoint directory is removed) is now treated as deleted on the subtree scan, which matches what a full library scan already does. Its files wait out the removal grace before the trash sweep, and the title returns if they come back within it.
Checklist
AI Disclosure