Merge pull request #339 from colincross/optimize_glob
Remove redundant stat/lstat calls from glob
This commit is contained in:
commit
49a8b95d4e
2 changed files with 23 additions and 17 deletions
|
@ -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.Mode()&os.ModeDir != 0 {
|
||||
dirs = append(dirs, f)
|
||||
subDirs, err := listDirsRecursiveRelative(fs, f, follow, depth)
|
||||
if err != nil {
|
||||
|
|
|
@ -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.Mode()&os.ModeDir != 0 {
|
||||
matches[i] = match + "/"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue