Richard Gomez 1 год назад
Родитель
Сommit
5407c44e0c
2 измененных файлов с 16 добавлено и 9 удалено
  1. 9 7
      detect/directory.go
  2. 7 2
      sources/directory.go

+ 9 - 7
detect/directory.go

@@ -13,10 +13,10 @@ import (
 
 func (d *Detector) DetectFiles(paths <-chan sources.ScanTarget) ([]report.Finding, error) {
 	for pa := range paths {
-		p := pa
 		d.Sema.Go(func() error {
-
-			f, err := os.Open(p.Path)
+			logger := log.With().Str("path", pa.Path).Logger()
+			log.Trace().Msgf("Scanning path: %s", pa)
+			f, err := os.Open(pa.Path)
 			if err != nil {
 				return err
 			}
@@ -31,7 +31,9 @@ func (d *Detector) DetectFiles(paths <-chan sources.ScanTarget) ([]report.Findin
 			if d.MaxTargetMegaBytes > 0 {
 				rawLength := fileSize / 1000000
 				if rawLength > int64(d.MaxTargetMegaBytes) {
-					log.Debug().Msgf("skipping file: %s scan due to size: %d", p.Path, rawLength)
+					logger.Debug().
+						Int64("size", rawLength).
+						Msgf("Skipping file: exceeds --max-target-megabytes")
 					return nil
 				}
 			}
@@ -62,10 +64,10 @@ func (d *Detector) DetectFiles(paths <-chan sources.ScanTarget) ([]report.Findin
 				totalLines += linesInChunk
 				fragment := Fragment{
 					Raw:      string(buf[:n]),
-					FilePath: p.Path,
+					FilePath: pa.Path,
 				}
-				if p.Symlink != "" {
-					fragment.SymlinkFile = p.Symlink
+				if pa.Symlink != "" {
+					fragment.SymlinkFile = pa.Symlink
 				}
 				for _, finding := range d.Detect(fragment) {
 					// need to add 1 since line counting starts at 1

+ 7 - 2
sources/directory.go

@@ -1,12 +1,12 @@
 package sources
 
 import (
+	"github.com/rs/zerolog/log"
 	"io/fs"
 	"os"
 	"path/filepath"
 
 	"github.com/fatih/semgroup"
-	"github.com/rs/zerolog/log"
 )
 
 type ScanTarget struct {
@@ -35,7 +35,12 @@ func DirectoryTargets(source string, s *semgroup.Group, followSymlinks bool) (<-
 						Symlink: "",
 					}
 				}
-				if fInfo.Mode().Type() == fs.ModeSymlink && followSymlinks {
+				if fInfo.Mode().Type() == fs.ModeSymlink {
+					if !followSymlinks {
+						log.Debug().Str("path", path).Msg("Skipping symlink")
+						return nil
+					}
+
 					realPath, err := filepath.EvalSymlinks(path)
 					if err != nil {
 						return err