Skip to content

Commit 43bf0b4

Browse files
authored
Merge pull request #12 from arduino/limit-recursiveness
Check IsDir error while doing recursive ReadDir
2 parents f1671f0 + 015d6db commit 43bf0b4

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

paths.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,9 @@ func (p *Path) ReadDirRecursive() (PathList, error) {
333333
path := p.Clone().Join(info.Name())
334334
paths.Add(path)
335335

336-
if path.IsDir() {
336+
if isDir, err := path.IsDirCheck(); err != nil {
337+
return nil, err
338+
} else if isDir {
337339
subPaths, err := path.ReadDirRecursive()
338340
if err != nil {
339341
return nil, err

paths_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
package paths
3131

3232
import (
33+
"os"
3334
"path/filepath"
3435
"runtime"
3536
"strings"
@@ -277,6 +278,19 @@ func TestReadDirRecursive(t *testing.T) {
277278
pathEqualsTo(t, "_testdata/symlinktofolder/subfolder/file4", list[13])
278279
pathEqualsTo(t, "_testdata/test.txt", list[14])
279280
pathEqualsTo(t, "_testdata/test.txt.gz", list[15])
281+
282+
// Test symlink loop
283+
tmp, err := MkTempDir("", "")
284+
require.NoError(t, err)
285+
defer tmp.RemoveAll()
286+
287+
folder := tmp.Join("folder")
288+
err = os.Symlink(tmp.String(), folder.String())
289+
require.NoError(t, err)
290+
291+
l, err := tmp.ReadDirRecursive()
292+
require.Error(t, err)
293+
require.Nil(t, l)
280294
}
281295

282296
func TestFilterDirs(t *testing.T) {

0 commit comments

Comments
 (0)