feat(dir): continue on permission error (#1621)

This commit is contained in:
Richard Gomez authored and GitHub committed 2024-11-05 07:58:36 -06:00
1 parent 202106a190
commit c1add1d268
2 files changed
+12 -1

No files matched your search

+5 -1
View File
@@ -15,9 +15,13 @@ func (d *Detector) DetectFiles(paths <-chan sources.ScanTarget) ([]report.Findin
for pa := range paths {
d.Sema.Go(func() error {
logger := log.With().Str("path", pa.Path).Logger()
log.Trace().Msgf("Scanning path: %s", pa)
logger.Trace().Msg("Scanning path")
f, err := os.Open(pa.Path)
if err != nil {
if os.IsPermission(err) {
logger.Warn().Msg("Skipping file: permission denied")
return nil
}
return err
}
defer f.Close()
+7
View File
@@ -20,9 +20,16 @@ func DirectoryTargets(source string, s *semgroup.Group, followSymlinks bool) (<-
defer close(paths)
return filepath.Walk(source,
func(path string, fInfo os.FileInfo, err error) error {
logger := log.With().Str("path", path).Logger()
if err != nil {
if os.IsPermission(err) {
// This seems to only fail on directories at this stage.
logger.Warn().Msg("Skipping directory: permission denied")
return filepath.SkipDir
}
return err
}
if fInfo.Name() == ".git" && fInfo.IsDir() {
return filepath.SkipDir
}