Repository navigation
fix(scanner): read .ignore patterns like Jellyfin - #1314
Conversation
Since #1133 the scanner has treated any .ignore file as "skip this whole directory". A library root whose .ignore lists folders to exclude, such as .downloads, was skipped entirely: full scans found zero files and stopped at the empty-root guard, while subtree scans marked the root's files missing and trash emptying deleted them after the removal grace. .ignore now follows Jellyfin's rules. An empty file, or one without a valid pattern, still skips its directory. Otherwise its lines are gitignore patterns, and only matching entries are skipped. .nomedia remains a whole-directory marker, and .siloignore is unchanged. A subtree scan whose configured library root is itself skipped now does nothing, leaving that root's catalog to a full library scan and its empty-root guard. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
There was a problem hiding this comment.
Quick104 has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Warning Review limit reachedNext included review available in 9 minutes. View limit detailsLimit details: You’ve used all 2 included reviews currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (8)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5d241bc16e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Go's path.Match negates a bracket expression only with "^" and has no POSIX classes, so a gitignore pattern such as [!a]*.mkv or Season [[:digit:]] matched different names than git and Jellyfin would, and could exclude the wrong media. Rewrite each bracket expression into path.Match syntax: "!" negates like "^", POSIX classes expand to ranges, and a leading "]" or a leading or trailing "-" is escaped as a literal. Unknown classes and unclosed brackets make the pattern invalid, so it is dropped. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f4747def6c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| for i := range len(name) + 1 { | ||
| if matchGlobSegments(rest, name[i:]) { |
There was a problem hiding this comment.
Memoize matches across repeated double-stars
A valid pattern containing several ** segments causes this recursive loop to recompute the same pattern/path suffix pairs combinatorially. For example, a nonmatching pattern with seven ** segments against a 30-segment path already takes about 200 ms for one entry, while ten segments exceed five seconds; applying such a rule across a large library can stall the scan. Memoize (pattern index, path index) results or use iterative dynamic programming so matching remains polynomial.
AGENTS.md reference: AGENTS.md:L13-L17
Useful? React with 👍 / 👎.
Problem
Related issue: N/A — narrow fix (regression from #1133)
Since #1133, the scanner skips any directory that contains an
.ignorefile, whatever the file says. Jellyfin reads a non-empty.ignoreas gitignore patterns. Libraries shared with Jellyfin often have one at the library root that lists download or recycle folders:In Silo that skips the whole root. On a deployment with this layout:
empty_rootwarning, so the empty-root guard held.Approach
.ignorenow follows Jellyfin's rules:.ignore, or one without a valid pattern, still skips its directory like.nomedia./anchoring, trailing/for directories only,**,!negation, and gitignore bracket expressions ([!a],[[:digit:]]), which are rewritten intopath.Matchsyntax. Nested files stack, and the last match wins.Silo matches anchored patterns relative to the
.ignorefile's directory, as git does. Jellyfin matches them against the absolute path. The two agree for plain names like the list above and can differ only for patterns that contain a/..nomediaand.siloignoreare unchanged.The per-directory marker and pattern handling moves into one helper,
dirIgnoreRules, which every walker (video, audiobook, podcast, ebook) now uses in place ofdirHasIgnoreMarkerpluschildIgnoreRules.ScanSubtreealso returns early when the configured library root is itself skipped. Without that check, a subtree scan under a skipped root walks nothing and retires the subtree piece by piece, outside the empty-root guard. The full library scan still decides what happens to a skipped root's catalog.The pattern matcher is about 50 lines. I wrote it rather than adding a gitignore dependency: go-git's matcher would pull in the go-git module for one package.
docs/architecture/scanner-ignore-files.mddocuments the new.ignoresemantics and the subtree rule.Validation
go test ./internal/scanner/...passes withSILO_TEST_DATABASE_URLpointed at a freshly migrated local Postgres, so the DB-gated dead-root, empty-root, and ignore suites ran..ignorewith patterns, walked both full and scoped.ignorevariants that still skip the directorylibraryRootSkippedScanSubtreeunder a skipped root, with.ignoreand.nomediarootsScanSubtreecheck makes the DB test fail the way the deployment did: the row is marked missing and deleted.golangci-lint run --new-from-merge-base=origin/main ./internal/scanner/...reports 0 issues.scripts/check-local-path-leaks.sh --cachedexits 0.Risks
.ignorewritten for feat(scanner): honor .ignore/.nomedia and .siloignore during scans #1133 to mean "skip this folder" now applies as patterns only. That matches Jellyfin, and an empty.ignorestill skips.missing_sinceon rows still in the catalog, re-adds deleted rows, and clears theempty_rootwarning.Checklist
AI Disclosure
🤖 Generated with Claude Code