// walk recursively descends path, calling walkFn. Copied, with some
// modifications from path/filepath.walk.
func walk(path string, info fs.FileInfo, walkFn filepath.WalkFunc) error {
- if !info.IsDir() {
- return walkFn(path, info, nil)
+ if err := walkFn(path, info, nil); err != nil || !info.IsDir() {
+ return err
}
- fis, readErr := ReadDir(path)
- walkErr := walkFn(path, info, readErr)
- // If readErr != nil, walk can't walk into this directory.
- // walkErr != nil means walkFn want walk to skip this directory or stop walking.
- // Therefore, if one of readErr and walkErr isn't nil, walk will return.
- if readErr != nil || walkErr != nil {
- // The caller's behavior is controlled by the return value, which is decided
- // by walkFn. walkFn may ignore readErr and return nil.
- // If walkFn returns SkipDir, it will be handled by the caller.
- // So walk should return whatever walkFn returns.
- return walkErr
+ fis, err := ReadDir(path)
+ if err != nil {
+ return walkFn(path, info, err)
}
for _, fi := range fis {
filename := filepath.Join(path, fi.Name())
- if walkErr = walk(filename, fi, walkFn); walkErr != nil {
- if !fi.IsDir() || walkErr != filepath.SkipDir {
- return walkErr
+ if err := walk(filename, fi, walkFn); err != nil {
+ if !fi.IsDir() || err != filepath.SkipDir {
+ return err
}
}
}
go list ./empty/...
stderr 'matched no packages'
-[root] stop # Root typically ignores file permissions.
-
# Make the directory ./noread unreadable, and verify that 'go list' reports an
# explicit error for a pattern that should match it (rather than treating it as
# equivalent to an empty directory).
+[root] stop # Root typically ignores file permissions.
[windows] skip # Does not have Unix-style directory permissions.
[plan9] skip # Might not have Unix-style directory permissions.