Skip to content

Check IsDir error while doing recursive ReadDir #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,9 @@ func (p *Path) ReadDirRecursive() (PathList, error) {
path := p.Clone().Join(info.Name())
paths.Add(path)

if path.IsDir() {
if isDir, err := path.IsDirCheck(); err != nil {
return nil, err
} else if isDir {
subPaths, err := path.ReadDirRecursive()
if err != nil {
return nil, err
Expand Down
14 changes: 14 additions & 0 deletions paths_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
package paths

import (
"os"
"path/filepath"
"runtime"
"strings"
Expand Down Expand Up @@ -277,6 +278,19 @@ func TestReadDirRecursive(t *testing.T) {
pathEqualsTo(t, "_testdata/symlinktofolder/subfolder/file4", list[13])
pathEqualsTo(t, "_testdata/test.txt", list[14])
pathEqualsTo(t, "_testdata/test.txt.gz", list[15])

// Test symlink loop
tmp, err := MkTempDir("", "")
require.NoError(t, err)
defer tmp.RemoveAll()

folder := tmp.Join("folder")
err = os.Symlink(tmp.String(), folder.String())
require.NoError(t, err)

l, err := tmp.ReadDirRecursive()
require.Error(t, err)
require.Nil(t, l)
}

func TestFilterDirs(t *testing.T) {
Expand Down