mirror of
https://github.com/navidrome/navidrome.git
synced 2026-10-11 11:57:12 +02:00
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.
This commit is contained in:
parent
c67c19c302
commit
3be40677fa
1 changed files with 5 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue