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 }