Skip to content

Commit

Permalink
fix(fs): handle default skip dirs properly (#6628)
Browse files Browse the repository at this point in the history
Signed-off-by: knqyf263 <[email protected]>
  • Loading branch information
knqyf263 authored May 4, 2024
1 parent 7a25dad commit 8016b82
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions pkg/fanal/walker/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ func NewFS() *FS {
// Walk walks the filesystem rooted at root, calling fn for each unfiltered file.
func (w *FS) Walk(root string, opt Option, fn WalkFunc) error {
opt.SkipFiles = w.BuildSkipPaths(root, opt.SkipFiles)
opt.SkipDirs = append(opt.SkipDirs, defaultSkipDirs...)
opt.SkipDirs = w.BuildSkipPaths(root, opt.SkipDirs)
opt.SkipDirs = append(opt.SkipDirs, defaultSkipDirs...)

walkDirFunc := w.WalkDirFunc(root, fn, opt)
walkDirFunc = w.onError(walkDirFunc)
Expand All @@ -50,24 +50,24 @@ func (w *FS) WalkDirFunc(root string, fn WalkFunc, opt Option) fs.WalkDirFunc {
}
relPath = filepath.ToSlash(relPath)

info, err := d.Info()
if err != nil {
return xerrors.Errorf("file info error: %w", err)
}

// Skip unnecessary files
switch {
case info.IsDir():
case d.IsDir():
if SkipPath(relPath, opt.SkipDirs) {
return filepath.SkipDir
}
return nil
case !info.Mode().IsRegular():
case !d.Type().IsRegular():
return nil
case SkipPath(relPath, opt.SkipFiles):
return nil
}

info, err := d.Info()
if err != nil {
return xerrors.Errorf("file info error: %w", err)
}

if err = fn(relPath, info, fileOpener(filePath)); err != nil {
return xerrors.Errorf("failed to analyze file: %w", err)
}
Expand All @@ -83,7 +83,7 @@ func (w *FS) onError(wrapped fs.WalkDirFunc) fs.WalkDirFunc {
// Unwrap fs.SkipDir error
case errors.Is(err, fs.SkipDir):
return fs.SkipDir
// ignore permission errors
// Ignore permission errors
case os.IsPermission(err):
return nil
case err != nil:
Expand Down

0 comments on commit 8016b82

Please sign in to comment.