mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-14 19:20:37 +03:00
Skip scanning folders if they contain a .ndignore
file. Closes #297
This commit is contained in:
parent
f82fefe0ab
commit
9e845cb116
@ -28,7 +28,8 @@ const (
|
|||||||
RequestThrottleBacklogLimit = 100
|
RequestThrottleBacklogLimit = 100
|
||||||
RequestThrottleBacklogTimeout = time.Minute
|
RequestThrottleBacklogTimeout = time.Minute
|
||||||
|
|
||||||
I18nFolder = "i18n"
|
I18nFolder = "i18n"
|
||||||
|
SkipScanFile = ".ndignore"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Cache options
|
// Cache options
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/deluan/navidrome/consts"
|
||||||
"github.com/deluan/navidrome/log"
|
"github.com/deluan/navidrome/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -66,7 +67,7 @@ func (s *ChangeDetector) loadDir(dirPath string) (children []string, lastUpdated
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if isDir {
|
if isDir && !IsDirIgnored(dirPath, f) {
|
||||||
children = append(children, filepath.Join(dirPath, f.Name()))
|
children = append(children, filepath.Join(dirPath, f.Name()))
|
||||||
} else {
|
} else {
|
||||||
if f.ModTime().After(lastUpdated) {
|
if f.ModTime().After(lastUpdated) {
|
||||||
@ -77,24 +78,29 @@ func (s *ChangeDetector) loadDir(dirPath string) (children []string, lastUpdated
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsDirOrSymlinkToDir returns true if and only if the Dirent represents a file
|
// IsDirOrSymlinkToDir returns true if and only if the dirent represents a file
|
||||||
// system directory, or a symbolic link to a directory. Note that if the Dirent
|
// system directory, or a symbolic link to a directory. Note that if the dirent
|
||||||
// is not a directory but is a symbolic link, this method will resolve by
|
// is not a directory but is a symbolic link, this method will resolve by
|
||||||
// sending a request to the operating system to follow the symbolic link.
|
// sending a request to the operating system to follow the symbolic link.
|
||||||
// Copied from github.com/karrick/godirwalk
|
// Copied from github.com/karrick/godirwalk
|
||||||
func IsDirOrSymlinkToDir(baseDir string, info os.FileInfo) (bool, error) {
|
func IsDirOrSymlinkToDir(baseDir string, dirent os.FileInfo) (bool, error) {
|
||||||
if info.IsDir() {
|
if dirent.IsDir() {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
if info.Mode()&os.ModeSymlink == 0 {
|
if dirent.Mode()&os.ModeSymlink == 0 {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
// Does this symlink point to a directory?
|
// Does this symlink point to a directory?
|
||||||
info, err := os.Stat(filepath.Join(baseDir, info.Name()))
|
dirent, err := os.Stat(filepath.Join(baseDir, dirent.Name()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
return info.IsDir(), nil
|
return dirent.IsDir(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsDirIgnored(baseDir string, dirent os.FileInfo) bool {
|
||||||
|
_, err := os.Stat(filepath.Join(baseDir, dirent.Name(), consts.SkipScanFile))
|
||||||
|
return err == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ChangeDetector) loadMap(dirMap dirInfoMap, path string, since time.Time, maybe bool) error {
|
func (s *ChangeDetector) loadMap(dirMap dirInfoMap, path string, since time.Time, maybe bool) error {
|
||||||
|
@ -129,6 +129,18 @@ var _ = Describe("ChangeDetector", func() {
|
|||||||
Expect(IsDirOrSymlinkToDir("tests/fixtures", dir)).To(BeFalse())
|
Expect(IsDirOrSymlinkToDir("tests/fixtures", dir)).To(BeFalse())
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Describe("IsDirIgnored", func() {
|
||||||
|
baseDir := filepath.Join("tests", "fixtures")
|
||||||
|
It("returns false for normal dirs", func() {
|
||||||
|
dir, _ := os.Stat(filepath.Join(baseDir, "empty_folder"))
|
||||||
|
Expect(IsDirIgnored(baseDir, dir)).To(BeFalse())
|
||||||
|
})
|
||||||
|
It("returns true when folder contains .ndignore file", func() {
|
||||||
|
dir, _ := os.Stat(filepath.Join(baseDir, "ignored_folder"))
|
||||||
|
Expect(IsDirIgnored(baseDir, dir)).To(BeTrue())
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// I hate time-based tests....
|
// I hate time-based tests....
|
||||||
|
0
tests/fixtures/ignored_folder/.ndignore
vendored
Normal file
0
tests/fixtures/ignored_folder/.ndignore
vendored
Normal file
Loading…
x
Reference in New Issue
Block a user