--max-target-megabytes flag now supported for --no-git flag as well (#1330)

This commit is contained in:
eyalatox authored and GitHub committed 2024-01-24 16:08:05 -06:00
1 parent a59289ca9b
commit 8b8920d4c3
3 files changed
+17 -4

No files matched your search

+16
View File
@@ -6,6 +6,7 @@ import (
"strings"
"github.com/h2non/filetype"
"github.com/rs/zerolog/log"
"github.com/zricethezav/gitleaks/v8/report"
"github.com/zricethezav/gitleaks/v8/sources"
)
@@ -14,12 +15,27 @@ func (d *Detector) DetectFiles(paths <-chan sources.ScanTarget) ([]report.Findin
for pa := range paths {
p := pa
d.Sema.Go(func() error {
f, err := os.Open(p.Path)
if err != nil {
return err
}
defer f.Close()
// Get file size
fileInfo, err := f.Stat()
if err != nil {
return err
}
fileSize := fileInfo.Size()
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)
return nil
}
}
// Buffer to hold file chunks
buf := make([]byte, chunkSize)
totalLines := 0