mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-29 04:34:46 +01:00
feat(dir): continue on permission error (#1621)
This commit is contained in:
1 parent
202106a190
commit
c1add1d268
2 files changed
+12
-1
No files matched your search
+5
-1
@@ -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()
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user