mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-03 20:47:35 +03:00
Ignore Recycle Bins in Windows. Fix #1074
This commit is contained in:
parent
47f15ccbc3
commit
339a6239fd
3 changed files with 46 additions and 2 deletions
|
@ -5,6 +5,7 @@ import (
|
|||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -159,10 +160,14 @@ func isDirOrSymlinkToDir(baseDir string, dirEnt fs.DirEntry) (bool, error) {
|
|||
// `ignore` file (named after consts.SkipScanFile)
|
||||
func isDirIgnored(baseDir string, dirEnt fs.DirEntry) bool {
|
||||
// allows Album folders for albums which e.g. start with ellipses
|
||||
if strings.HasPrefix(dirEnt.Name(), ".") && !strings.HasPrefix(dirEnt.Name(), "..") {
|
||||
name := dirEnt.Name()
|
||||
if strings.HasPrefix(name, ".") && !strings.HasPrefix(name, "..") {
|
||||
return true
|
||||
}
|
||||
_, err := os.Stat(filepath.Join(baseDir, dirEnt.Name(), consts.SkipScanFile))
|
||||
if runtime.GOOS == "windows" && strings.EqualFold(name, "$RECYCLE.BIN") {
|
||||
return true
|
||||
}
|
||||
_, err := os.Stat(filepath.Join(baseDir, name, consts.SkipScanFile))
|
||||
return err == nil
|
||||
}
|
||||
|
||||
|
|
|
@ -79,6 +79,10 @@ var _ = Describe("walk_dir_tree", func() {
|
|||
dirEntry, _ := getDirEntry(baseDir, "...unhidden_folder")
|
||||
Expect(isDirIgnored(baseDir, dirEntry)).To(BeFalse())
|
||||
})
|
||||
It("returns false when folder name is $Recycle.Bin", func() {
|
||||
dirEntry, _ := getDirEntry(baseDir, "$Recycle.Bin")
|
||||
Expect(isDirIgnored(baseDir, dirEntry)).To(BeFalse())
|
||||
})
|
||||
})
|
||||
|
||||
Describe("fullReadDir", func() {
|
||||
|
|
35
scanner/walk_dir_tree_windows_test.go
Normal file
35
scanner/walk_dir_tree_windows_test.go
Normal file
|
@ -0,0 +1,35 @@
|
|||
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