Skip to content

Commit 4aa0f1c

Browse files
committed
In ReadDirRecursive do not try to recurse into broken symlinks
Instead return the symlink as a file in the file list
1 parent 3226a11 commit 4aa0f1c

File tree

2 files changed

+2
-14
lines changed

2 files changed

+2
-14
lines changed

Diff for: readdir.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,7 @@ func (p *Path) ReadDirRecursiveFiltered(recursionFilter ReadDirFilter, filters .
116116
}
117117

118118
if recursionFilter == nil || recursionFilter(path) {
119-
if isDir, err := path.IsDirCheck(); err != nil {
120-
return nil, err
121-
} else if isDir {
119+
if path.IsDir() {
122120
subPaths, err := search(path)
123121
if err != nil {
124122
return nil, err

Diff for: readdir_test.go

+1-11
Original file line numberDiff line numberDiff line change
@@ -250,21 +250,11 @@ func TestReadDirRecursiveFiltered(t *testing.T) {
250250
func TestReadDirRecursiveLoopDetection(t *testing.T) {
251251
loopsPath := New("testdata", "loops")
252252
unbuondedReaddir := func(testdir string) (PathList, error) {
253-
// This is required to unbound the recursion, otherwise it will stop
254-
// when the paths becomes too long due to the symlink loop: this is not
255-
// what we want, we are looking for an early detection of the loop.
256-
skipBrokenLinks := func(p *Path) bool {
257-
_, err := p.Stat()
258-
return err == nil
259-
}
260-
261253
var files PathList
262254
var err error
263255
done := make(chan bool)
264256
go func() {
265-
files, err = loopsPath.Join(testdir).ReadDirRecursiveFiltered(
266-
skipBrokenLinks,
267-
)
257+
files, err = loopsPath.Join(testdir).ReadDirRecursive()
268258
done <- true
269259
}()
270260
require.Eventually(

0 commit comments

Comments
 (0)