diff --git a/pathtools/fs.go b/pathtools/fs.go index 21754d0..81a4328 100644 --- a/pathtools/fs.go +++ b/pathtools/fs.go @@ -538,10 +538,22 @@ func listDirsRecursiveRelative(fs FileSystem, name string, follow ShouldFollowSy continue } f = filepath.Join(name, f) - if isSymlink, _ := fs.IsSymlink(f); isSymlink && follow == DontFollowSymlinks { - continue + var info os.FileInfo + if follow == DontFollowSymlinks { + info, err = fs.Lstat(f) + if err != nil { + continue + } + if info.Mode()&os.ModeSymlink != 0 { + continue + } + } else { + info, err = fs.Stat(f) + if err != nil { + continue + } } - if isDir, _ := fs.IsDir(f); isDir { + if info.IsDir() { dirs = append(dirs, f) subDirs, err := listDirsRecursiveRelative(fs, f, follow, depth) if err != nil { diff --git a/pathtools/glob.go b/pathtools/glob.go index 727b725..6a30e8d 100644 --- a/pathtools/glob.go +++ b/pathtools/glob.go @@ -76,24 +76,18 @@ func startGlob(fs FileSystem, pattern string, excludes []string, } for i, match := range matches { - isSymlink, err := fs.IsSymlink(match) + var info os.FileInfo + if follow == DontFollowSymlinks { + info, err = fs.Lstat(match) + } else { + info, err = fs.Stat(match) + } if err != nil { return nil, nil, err } - if !(isSymlink && follow == DontFollowSymlinks) { - isDir, err := fs.IsDir(match) - if os.IsNotExist(err) { - if isSymlink { - return nil, nil, fmt.Errorf("%s: dangling symlink", match) - } - } - if err != nil { - return nil, nil, fmt.Errorf("%s: %s", match, err.Error()) - } - if isDir { - matches[i] = match + "/" - } + if info.IsDir() { + matches[i] = match + "/" } }