From 3be40677faa75ab3d9c7d73f2524264fb1365fcc Mon Sep 17 00:00:00 2001 From: Deluan Date: Mon, 14 Sep 2026 08:55:45 -0400 Subject: [PATCH] refactor(scanner): share the ignore-all pattern constant Use a single ignoreAllPattern constant for both the .nomedia and the empty .ndignore cases, so the two can't drift apart. --- scanner/ignore_checker.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/scanner/ignore_checker.go b/scanner/ignore_checker.go index bf50a46d1..d65d3791e 100644 --- a/scanner/ignore_checker.go +++ b/scanner/ignore_checker.go @@ -12,6 +12,8 @@ import ( ignore "github.com/sabhiram/go-gitignore" ) +const ignoreAllPattern = "**/*" + // IgnoreChecker manages .ndignore patterns using a stack-based approach. // Use Push() to add patterns when entering a folder, Pop() when leaving, // and ShouldIgnore() to check if a path should be ignored. @@ -102,11 +104,11 @@ func (ic *IgnoreChecker) ShouldIgnore(ctx context.Context, relPath string) bool // loadPatternsFromFolder reads the .ndignore file in the specified folder and returns the patterns. // If the file doesn't exist, returns an empty slice. -// If the file exists but is empty, or a .nomedia file exists, returns a pattern to ignore everything ("**/*"). +// If the file exists but is empty, or a .nomedia file exists, returns a pattern to ignore everything. func (ic *IgnoreChecker) loadPatternsFromFolder(ctx context.Context, folder string) []string { if _, err := fs.Stat(ic.fsys, path.Join(folder, consts.NoMediaFile)); err == nil { log.Trace(ctx, "Scanner: .nomedia file found, ignoring everything", "path", folder) - return []string{"**/*"} + return []string{ignoreAllPattern} } ignoreFilePath := path.Join(folder, consts.ScanIgnoreFile) @@ -143,7 +145,7 @@ func (ic *IgnoreChecker) loadPatternsFromFolder(ctx context.Context, folder stri // If the .ndignore file is empty, ignore everything if len(patterns) == 0 { log.Trace(ctx, "Scanner: .ndignore file is empty, ignoring everything", "path", folder) - patterns = []string{"**/*"} + patterns = []string{ignoreAllPattern} } return patterns