Skip to content

Commit

Permalink
fastwalk: save a call to Stat when following links
Browse files Browse the repository at this point in the history
This also changes the code to immediately check if root exists.
  • Loading branch information
charlievieth committed Apr 6, 2024
1 parent 386c69b commit 9e83309
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions fastwalk.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,14 @@ type DirEntry interface {
// sentinel error. It is the walkFn's responsibility to prevent
// Walk from going into symlink cycles.
func Walk(conf *Config, root string, walkFn fs.WalkDirFunc) error {
fi, err := os.Stat(root)
if err != nil {
return err
}
if conf == nil {
dupe := DefaultConfig
conf = &dupe
}
fi, err := os.Lstat(root)
if err != nil {
return err
}

// Make sure to wait for all workers to finish, otherwise
// walkFn could still be called after returning. This Wait call
Expand All @@ -190,9 +190,7 @@ func Walk(conf *Config, root string, walkFn fs.WalkDirFunc) error {
follow: conf.Follow,
}
if w.follow {
if fi, err := os.Stat(root); err == nil {
w.ignoredDirs = append(w.ignoredDirs, fi)
}
w.ignoredDirs = append(w.ignoredDirs, fi)
}

defer close(w.donec)
Expand Down

0 comments on commit 9e83309

Please sign in to comment.