Fix ignoring hidden folders when scanning

This commit is contained in:
Deluan 2020-10-22 13:59:54 -04:00
parent f9e0de31b8
commit 4514a54744
3 changed files with 8 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"time"
"github.com/deluan/navidrome/consts"
@ -105,6 +106,9 @@ func isDirOrSymlinkToDir(baseDir string, dirInfo os.FileInfo) (bool, error) {
// isDirIgnored returns true if the directory represented by dirInfo contains an
// `ignore` file (named after consts.SkipScanFile)
func isDirIgnored(baseDir string, dirInfo os.FileInfo) bool {
if strings.HasPrefix(dirInfo.Name(), ".") {
return true
}
_, err := os.Stat(filepath.Join(baseDir, dirInfo.Name(), consts.SkipScanFile))
return err == nil
}

View File

@ -38,5 +38,9 @@ var _ = Describe("load_tree", func() {
dir, _ := os.Stat(filepath.Join(baseDir, "ignored_folder"))
Expect(isDirIgnored(baseDir, dir)).To(BeTrue())
})
It("returns true when folder name starts with a `.`", func() {
dir, _ := os.Stat(filepath.Join(baseDir, ".hidden_folder"))
Expect(isDirIgnored(baseDir, dir)).To(BeTrue())
})
})
})

View File