mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-04 21:17:37 +03:00
Ignore #snapshot folders when scanning. Fixes #3257
This commit is contained in:
parent
a1866c7ff3
commit
9ae2ec1a07
3 changed files with 13 additions and 40 deletions
|
@ -5,7 +5,7 @@ import (
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"slices"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -160,6 +160,11 @@ func isDirOrSymlinkToDir(baseDir string, dirEnt fs.DirEntry) (bool, error) {
|
||||||
return fileInfo.IsDir(), nil
|
return fileInfo.IsDir(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var ignoredDirs = []string{
|
||||||
|
"$RECYCLE.BIN",
|
||||||
|
"#snapshot",
|
||||||
|
}
|
||||||
|
|
||||||
// isDirIgnored returns true if the directory represented by dirEnt contains an
|
// isDirIgnored returns true if the directory represented by dirEnt contains an
|
||||||
// `ignore` file (named after skipScanFile)
|
// `ignore` file (named after skipScanFile)
|
||||||
func isDirIgnored(baseDir string, dirEnt fs.DirEntry) bool {
|
func isDirIgnored(baseDir string, dirEnt fs.DirEntry) bool {
|
||||||
|
@ -168,8 +173,7 @@ func isDirIgnored(baseDir string, dirEnt fs.DirEntry) bool {
|
||||||
if strings.HasPrefix(name, ".") && !strings.HasPrefix(name, "..") {
|
if strings.HasPrefix(name, ".") && !strings.HasPrefix(name, "..") {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
if slices.IndexFunc(ignoredDirs, func(s string) bool { return strings.EqualFold(s, name) }) != -1 {
|
||||||
if runtime.GOOS == "windows" && strings.EqualFold(name, "$RECYCLE.BIN") {
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
_, err := os.Stat(filepath.Join(baseDir, name, consts.SkipScanFile))
|
_, err := os.Stat(filepath.Join(baseDir, name, consts.SkipScanFile))
|
||||||
|
|
|
@ -82,9 +82,13 @@ var _ = Describe("walk_dir_tree", func() {
|
||||||
dirEntry := getDirEntry(baseDir, "...unhidden_folder")
|
dirEntry := getDirEntry(baseDir, "...unhidden_folder")
|
||||||
Expect(isDirIgnored(baseDir, dirEntry)).To(BeFalse())
|
Expect(isDirIgnored(baseDir, dirEntry)).To(BeFalse())
|
||||||
})
|
})
|
||||||
It("returns false when folder name is $Recycle.Bin", func() {
|
It("returns true when folder name is $Recycle.Bin", func() {
|
||||||
dirEntry := getDirEntry(baseDir, "$Recycle.Bin")
|
dirEntry := getDirEntry(baseDir, "$Recycle.Bin")
|
||||||
Expect(isDirIgnored(baseDir, dirEntry)).To(BeFalse())
|
Expect(isDirIgnored(baseDir, dirEntry)).To(BeTrue())
|
||||||
|
})
|
||||||
|
It("returns true when folder name is #snapshot", func() {
|
||||||
|
dirEntry := getDirEntry(baseDir, "#snapshot")
|
||||||
|
Expect(isDirIgnored(baseDir, dirEntry)).To(BeTrue())
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -1,35 +0,0 @@
|
||||||
package scanner
|
|
||||||
|
|
||||||
import (
|
|
||||||
"path/filepath"
|
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
|
||||||
. "github.com/onsi/gomega"
|
|
||||||
)
|
|
||||||
|
|
||||||
var _ = Describe("walk_dir_tree_windows", func() {
|
|
||||||
baseDir := filepath.Join("tests", "fixtures")
|
|
||||||
|
|
||||||
Describe("isDirIgnored", func() {
|
|
||||||
It("returns false for normal dirs", func() {
|
|
||||||
dirEntry, _ := getDirEntry(baseDir, "empty_folder")
|
|
||||||
Expect(isDirIgnored(baseDir, dirEntry)).To(BeFalse())
|
|
||||||
})
|
|
||||||
It("returns true when folder contains .ndignore file", func() {
|
|
||||||
dirEntry, _ := getDirEntry(baseDir, "ignored_folder")
|
|
||||||
Expect(isDirIgnored(baseDir, dirEntry)).To(BeTrue())
|
|
||||||
})
|
|
||||||
It("returns true when folder name starts with a `.`", func() {
|
|
||||||
dirEntry, _ := getDirEntry(baseDir, ".hidden_folder")
|
|
||||||
Expect(isDirIgnored(baseDir, dirEntry)).To(BeTrue())
|
|
||||||
})
|
|
||||||
It("returns false when folder name starts with ellipses", func() {
|
|
||||||
dirEntry, _ := getDirEntry(baseDir, "...unhidden_folder")
|
|
||||||
Expect(isDirIgnored(baseDir, dirEntry)).To(BeFalse())
|
|
||||||
})
|
|
||||||
It("returns true when folder name is $Recycle.Bin", func() {
|
|
||||||
dirEntry, _ := getDirEntry(baseDir, "$Recycle.Bin")
|
|
||||||
Expect(isDirIgnored(baseDir, dirEntry)).To(BeTrue())
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
Loading…
Add table
Add a link
Reference in a new issue