mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-28 20:24:22 +01:00
chore: log skipped symlinks (#1591)
This commit is contained in:
1 parent
d03d6c401b
commit
5407c44e0c
2 files changed
+16
-9
No files matched your search
+9
-7
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user