Index: Ignore files and folders starting with @ #1543

Synology stores hidden sidecar / thumbnail files in @eaDir.
This commit is contained in:
Michael Mayer 2021-09-24 01:24:36 +02:00
parent 7251208e4c
commit 2929733f78
3 changed files with 44 additions and 1 deletions

View file

@ -156,7 +156,7 @@ func (l *IgnoreList) Ignore(fileName string) bool {
}
}
if l.ignoreHidden && strings.HasPrefix(filepath.Base(fileName), ".") {
if l.ignoreHidden && FileNameHidden(fileName) {
l.hiddenFiles = append(l.hiddenFiles, fileName)
return true
}

View file

@ -53,3 +53,21 @@ func RelName(fileName, dir string) string {
return fileName
}
// FileNameHidden tests is a file name belongs to a hidden file.
func FileNameHidden(name string) bool {
if name == "" {
return false
}
name = filepath.Base(name)
prefix := name[0:1]
switch prefix {
case ".", "@":
return true
default:
return false
}
}

View file

@ -67,3 +67,28 @@ func TestFileName(t *testing.T) {
assert.Equal(t, "testdata/FOO.XMP.jpeg", result)
})
}
func TestFileNameHidden(t *testing.T) {
t.Run("AtPrefix", func(t *testing.T) {
assert.True(t, FileNameHidden("/some/path/@eaDir"))
})
t.Run("DotPrefix", func(t *testing.T) {
assert.True(t, FileNameHidden("/some/.folder"))
})
t.Run("HasAts", func(t *testing.T) {
assert.False(t, FileNameHidden("/some/path/ea@Dir"))
assert.False(t, FileNameHidden("/some/@path/ea@Dir"))
assert.False(t, FileNameHidden("@/eaDir"))
})
t.Run("HasDots", func(t *testing.T) {
assert.False(t, FileNameHidden("/some/image.jpg."))
assert.False(t, FileNameHidden("./.some/foo"))
})
t.Run("False", func(t *testing.T) {
assert.False(t, FileNameHidden("/some/path/folder"))
})
t.Run("Empty", func(t *testing.T) {
assert.False(t, FileNameHidden(""))
})
}