Skip to content

Commit

Permalink
Merge a4976b5 into 5003ed8
Browse files Browse the repository at this point in the history
  • Loading branch information
auxten committed Mar 10, 2022
2 parents 5003ed8 + a4976b5 commit 3285136
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/path/filepath/path.go
Expand Up @@ -462,11 +462,12 @@ func walk(path string, info fs.FileInfo, walkFn WalkFunc) error {
//
// WalkDir does not follow symbolic links.
func WalkDir(root string, fn fs.WalkDirFunc) error {
info, err := os.Lstat(root)
cleanRootPath := Clean(root)
info, err := os.Lstat(cleanRootPath)
if err != nil {
err = fn(root, nil, err)
err = fn(cleanRootPath, nil, err)
} else {
err = walkDir(root, &statDirEntry{info}, fn)
err = walkDir(cleanRootPath, &statDirEntry{info}, fn)
}
if err == SkipDir {
return nil
Expand Down Expand Up @@ -498,11 +499,12 @@ func (d *statDirEntry) Info() (fs.FileInfo, error) { return d.info, nil }
// Walk is less efficient than WalkDir, introduced in Go 1.16,
// which avoids calling os.Lstat on every visited file or directory.
func Walk(root string, fn WalkFunc) error {
info, err := os.Lstat(root)
cleanRootPath := Clean(root)
info, err := os.Lstat(cleanRootPath)
if err != nil {
err = fn(root, nil, err)
err = fn(cleanRootPath, nil, err)
} else {
err = walk(root, info, fn)
err = walk(cleanRootPath, info, fn)
}
if err == SkipDir {
return nil
Expand Down

0 comments on commit 3285136

Please sign in to comment.