fix(library): hidden files and folders are not part of the library (#8305)
A full scan, the watcher's directory watches and the files it queues all skip any name below a library root that starts with a dot. A download manager can park replaced copies in a hidden folder, and macOS leaves "._" files beside the music; neither is a track. A track already indexed from a hidden path is marked missing at the next full scan. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package library
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Hidden files and folders, whose names start with a dot, are not part of
|
||||
// the library. Other programs that share the music folder keep their own
|
||||
// things there: a download manager parks the copies it replaced in a hidden
|
||||
// folder until someone empties it, and macOS leaves "._" files beside every
|
||||
// track it copies. Indexing them would list a copy the person set aside, or
|
||||
// adopt it as the original track having moved. Navidrome and Jellyfin skip
|
||||
// them the same way.
|
||||
|
||||
// hiddenName reports whether a file or folder name is hidden.
|
||||
func hiddenName(name string) bool {
|
||||
return strings.HasPrefix(name, ".") && name != "." && name != ".."
|
||||
}
|
||||
|
||||
// hiddenInLibrary reports whether path is, or sits inside, a hidden file or
|
||||
// folder below one of the library roots. A root may itself be hidden; only
|
||||
// what is below it counts.
|
||||
func hiddenInLibrary(roots []string, path string) bool {
|
||||
for _, root := range roots {
|
||||
rel, err := filepath.Rel(root, path)
|
||||
if err != nil || rel == "." || rel == ".." || strings.HasPrefix(rel, ".."+string(filepath.Separator)) {
|
||||
continue
|
||||
}
|
||||
for _, part := range strings.Split(rel, string(filepath.Separator)) {
|
||||
if hiddenName(part) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
return false
|
||||
}
|
||||
Reference in New Issue
Block a user