Skip to content

fix(scanner): read .ignore patterns like Jellyfin - #1314

Merged
Quick104 merged 2 commits into
mainfrom
fix/scanner-ignore-file-patterns
Sep 22, 2026
Merged

Quick104 merged 2 commits into
mainfrom
fix/scanner-ignore-file-patterns

Conversation

@Quick104

@Quick104 Quick104 commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: N/A — narrow fix (regression from #1133)

Since #1133, the scanner skips any directory that contains an .ignore file, whatever the file says. Jellyfin reads a non-empty .ignore as gitignore patterns. Libraries shared with Jellyfin often have one at the library root that lists download or recycle folders:

.recyclebin
.downloads
.inbound

In Silo that skips the whole root. On a deployment with this layout:

  • Full library scans found zero files and set the empty_root warning, so the empty-root guard held.
  • Subtree scans have no such guard. They found zero files, marked the root's present files missing, and trash emptying deleted those rows once the 24-hour removal grace passed.

Approach

.ignore now follows Jellyfin's rules:

  • An empty .ignore, or one without a valid pattern, still skips its directory like .nomedia.
  • Otherwise each line is a gitignore pattern and only matching entries are skipped. Supported syntax: unanchored names at any depth, / anchoring, trailing / for directories only, **, ! negation, and gitignore bracket expressions ([!a], [[:digit:]]), which are rewritten into path.Match syntax. Nested files stack, and the last match wins.

Silo matches anchored patterns relative to the .ignore file'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 /. .nomedia and .siloignore are unchanged.

The per-directory marker and pattern handling moves into one helper, dirIgnoreRules, which every walker (video, audiobook, podcast, ebook) now uses in place of dirHasIgnoreMarker plus childIgnoreRules.

ScanSubtree also 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.md documents the new .ignore semantics and the subtree rule.

Validation

  • go test ./internal/scanner/... passes with SILO_TEST_DATABASE_URL pointed at a freshly migrated local Postgres, so the DB-gated dead-root, empty-root, and ignore suites ran.
  • New tests:
    • the production layout: a root .ignore with patterns, walked both full and scoped
    • pattern-less .ignore variants that still skip the directory
    • a gitignore semantics table, including bracket negation, POSIX classes, and malformed brackets
    • nested negation
    • a directory-only pattern on a symlinked directory
    • libraryRootSkipped
    • ScanSubtree under a skipped root, with .ignore and .nomedia roots
  • Disabling the new ScanSubtree check 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.
  • The pre-commit path-leak hook crashed with a bus error under macOS bash 3.2, so the commit skipped the hook. Run directly, scripts/check-local-path-leaks.sh --cached exits 0.

Risks

  • A non-empty .ignore written 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 .ignore still skips.
  • Subtree scans under a skipped library root no longer retire anything. Full scans handle that root as before.
  • Deployments already hit by this bug need a full scan of the affected libraries after upgrading. That scan finds the files, clears missing_since on rows still in the catalog, re-adds deleted rows, and clears the empty_root warning.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.

AI Disclosure

  • Harness: Claude Code
  • Tool(s): Claude Code
  • Model(s): claude-opus-5-5
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: n/a. The author reviewed the diff and confirmed the new subtree test fails without the fix. No independent review was run.

🤖 Generated with Claude Code

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]>

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick104 has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-22T20:09:34.716304Z f4747de New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 9 minutes.

Check out review usage here.

View limit details

Limit 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.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 4ae5f66f-8959-48de-8bf8-7b6a468914b9

📥 Commits

Reviewing files that changed from the base of the PR and between 61eb515 and f4747de.

📒 Files selected for processing (8)
  • docs/architecture/scanner-ignore-files.md
  • internal/scanner/audiobook_scan.go
  • internal/scanner/ignore.go
  • internal/scanner/ignore_scan_test.go
  • internal/scanner/ignore_test.go
  • internal/scanner/podcast.go
  • internal/scanner/podcast_scan.go
  • internal/scanner/scanner.go

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread internal/scanner/ignore.go Resolved
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]>
@Quick104
Quick104 merged commit a588e1e into main Sep 22, 2026
11 checks passed
@Quick104
Quick104 deleted the fix/scanner-ignore-file-patterns branch September 22, 2026 20:04

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +318 to +319
for i := range len(name) + 1 {
if matchGlobSegments(rest, name[i:]) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant