Skip to content

Commit 429170e

Browse files
Fix FilterOutDirs on broken symlinks
Broken symlinks would previously be treated as directories and filtered out, due to the use of IsNotDir (which defaults to false on Stat errors), but it makes more sense to only filter out elements that are certainly directories, so use IsDir (which also defaults to false on Stat errors) and negate its result.
1 parent fed0409 commit 429170e

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

list.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (p *PathList) FilterDirs() {
7878
func (p *PathList) FilterOutDirs() {
7979
res := (*p)[:0]
8080
for _, path := range *p {
81-
if path.IsNotDir() {
81+
if !path.IsDir() {
8282
res = append(res, path)
8383
}
8484
}

paths_test.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,12 @@ func TestFilterOutDirs(t *testing.T) {
348348
pathEqualsTo(t, "_testdata/test.txt.gz", list[6])
349349

350350
list.FilterOutDirs()
351-
require.Len(t, list, 4)
351+
require.Len(t, list, 5)
352352
pathEqualsTo(t, "_testdata/anotherFile", list[0])
353-
pathEqualsTo(t, "_testdata/file", list[1])
354-
pathEqualsTo(t, "_testdata/test.txt", list[2])
355-
pathEqualsTo(t, "_testdata/test.txt.gz", list[3])
353+
pathEqualsTo(t, "_testdata/brokensymlink", list[1])
354+
pathEqualsTo(t, "_testdata/file", list[2])
355+
pathEqualsTo(t, "_testdata/test.txt", list[3])
356+
pathEqualsTo(t, "_testdata/test.txt.gz", list[4])
356357
}
357358

358359
func TestEquivalentPaths(t *testing.T) {

0 commit comments

Comments
 (0)