Index: Ignore paths starting with _. and __ like "__MACOSX" #2844
Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
parent
9be52990fa
commit
7c634a1f51
2 changed files with 17 additions and 6 deletions
|
@ -56,18 +56,27 @@ func RelName(fileName, dir string) string {
|
|||
|
||||
// FileNameHidden tests is a file name belongs to a hidden file.
|
||||
func FileNameHidden(name string) bool {
|
||||
if name == "" {
|
||||
if len(name) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
name = filepath.Base(name)
|
||||
|
||||
prefix := name[0:1]
|
||||
|
||||
switch prefix {
|
||||
// Hidden files and folders starting with "." or "@" should be ignored.
|
||||
switch name[0:1] {
|
||||
case ".", "@":
|
||||
return true
|
||||
default:
|
||||
return strings.HasPrefix(name, "_.")
|
||||
}
|
||||
|
||||
if len(name) == 1 {
|
||||
return false
|
||||
}
|
||||
|
||||
// File paths starting with _. and __ like __MACOSX should be ignored.
|
||||
switch name[0:2] {
|
||||
case "_.", "__":
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -85,6 +85,8 @@ func TestFileNameHidden(t *testing.T) {
|
|||
assert.False(t, FileNameHidden("_folder"))
|
||||
assert.True(t, FileNameHidden("/some/_.folder"))
|
||||
assert.True(t, FileNameHidden("_.folder"))
|
||||
assert.True(t, FileNameHidden("/some/__MACOSX"))
|
||||
assert.True(t, FileNameHidden("__MACOSX"))
|
||||
})
|
||||
t.Run("At", func(t *testing.T) {
|
||||
assert.False(t, FileNameHidden("/some/path/ea@Dir"))
|
||||
|
|
Loading…
Reference in a new issue