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:
@@ -176,6 +176,9 @@ func (w *Watcher) eventLoop(ctx context.Context, fsw *fsnotify.Watcher, batches
|
||||
func (w *Watcher) handleEvent(
|
||||
fsw *fsnotify.Watcher, event fsnotify.Event, pending map[string]struct{},
|
||||
) bool {
|
||||
if hiddenInLibrary(w.scanner.Roots(), event.Name) {
|
||||
return false
|
||||
}
|
||||
info, err := os.Stat(event.Name)
|
||||
isDir := err == nil && info.IsDir()
|
||||
isAudio := audioExtensions[strings.ToLower(filepath.Ext(event.Name))]
|
||||
@@ -230,13 +233,17 @@ func (w *Watcher) process(ctx context.Context, paths []string) {
|
||||
}
|
||||
}
|
||||
|
||||
// addRecursive adds an fsnotify watch for root and every subdirectory under it.
|
||||
// Per-directory failures (inotify limits, permissions) are logged and skipped.
|
||||
// addRecursive adds an fsnotify watch for root and every subdirectory under it
|
||||
// that is not hidden. Per-directory failures (inotify limits, permissions) are
|
||||
// logged and skipped.
|
||||
func (w *Watcher) addRecursive(fsw *fsnotify.Watcher, root string) {
|
||||
_ = filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error {
|
||||
if err != nil || !d.IsDir() {
|
||||
return nil //nolint:nilerr // tolerate unreadable subtrees
|
||||
}
|
||||
if path != root && hiddenName(d.Name()) {
|
||||
return fs.SkipDir
|
||||
}
|
||||
if aerr := fsw.Add(path); aerr != nil {
|
||||
w.logger.Warn("library watcher: add watch failed", "path", path, "err", aerr)
|
||||
}
|
||||
@@ -249,9 +256,18 @@ func (w *Watcher) addRecursive(fsw *fsnotify.Watcher, root string) {
|
||||
func (w *Watcher) enqueueDirAudio(dir string, pending map[string]struct{}) bool {
|
||||
added := false
|
||||
_ = filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error {
|
||||
if err != nil || d.IsDir() {
|
||||
if err != nil {
|
||||
return nil //nolint:nilerr // tolerate unreadable subtrees
|
||||
}
|
||||
if path != dir && hiddenName(d.Name()) {
|
||||
if d.IsDir() {
|
||||
return fs.SkipDir
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if d.IsDir() {
|
||||
return nil
|
||||
}
|
||||
if audioExtensions[strings.ToLower(filepath.Ext(path))] {
|
||||
pending[path] = struct{}{}
|
||||
added = true
|
||||
|
||||
Reference in New Issue
Block a user