Ignore #snapshot folders when scanning. Fixes #3257

This commit is contained in:
Deluan 2024-09-13 17:30:08 -04:00
parent a1866c7ff3
commit 9ae2ec1a07
3 changed files with 13 additions and 40 deletions

View file

@ -5,7 +5,7 @@ import (
"io/fs"
"os"
"path/filepath"
"runtime"
"slices"
"sort"
"strings"
"time"
@ -160,6 +160,11 @@ func isDirOrSymlinkToDir(baseDir string, dirEnt fs.DirEntry) (bool, error) {
return fileInfo.IsDir(), nil
}
var ignoredDirs = []string{
"$RECYCLE.BIN",
"#snapshot",
}
// isDirIgnored returns true if the directory represented by dirEnt contains an
// `ignore` file (named after skipScanFile)
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, "..") {
return true
}
if runtime.GOOS == "windows" && strings.EqualFold(name, "$RECYCLE.BIN") {
if slices.IndexFunc(ignoredDirs, func(s string) bool { return strings.EqualFold(s, name) }) != -1 {
return true
}
_, err := os.Stat(filepath.Join(baseDir, name, consts.SkipScanFile))

View file

@ -82,9 +82,13 @@ 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() {
It("returns true when folder name is $Recycle.Bin", func() {
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())
})
})

View file

@ -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())
})
})
})