mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-12-01 13:34:23 +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) {
|
func (d *Detector) DetectFiles(paths <-chan sources.ScanTarget) ([]report.Finding, error) {
|
||||||
for pa := range paths {
|
for pa := range paths {
|
||||||
p := pa
|
|
||||||
d.Sema.Go(func() error {
|
d.Sema.Go(func() error {
|
||||||
|
logger := log.With().Str("path", pa.Path).Logger()
|
||||||
f, err := os.Open(p.Path)
|
log.Trace().Msgf("Scanning path: %s", pa)
|
||||||
|
f, err := os.Open(pa.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -31,7 +31,9 @@ func (d *Detector) DetectFiles(paths <-chan sources.ScanTarget) ([]report.Findin
|
|||||||
if d.MaxTargetMegaBytes > 0 {
|
if d.MaxTargetMegaBytes > 0 {
|
||||||
rawLength := fileSize / 1000000
|
rawLength := fileSize / 1000000
|
||||||
if rawLength > int64(d.MaxTargetMegaBytes) {
|
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
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -62,10 +64,10 @@ func (d *Detector) DetectFiles(paths <-chan sources.ScanTarget) ([]report.Findin
|
|||||||
totalLines += linesInChunk
|
totalLines += linesInChunk
|
||||||
fragment := Fragment{
|
fragment := Fragment{
|
||||||
Raw: string(buf[:n]),
|
Raw: string(buf[:n]),
|
||||||
FilePath: p.Path,
|
FilePath: pa.Path,
|
||||||
}
|
}
|
||||||
if p.Symlink != "" {
|
if pa.Symlink != "" {
|
||||||
fragment.SymlinkFile = p.Symlink
|
fragment.SymlinkFile = pa.Symlink
|
||||||
}
|
}
|
||||||
for _, finding := range d.Detect(fragment) {
|
for _, finding := range d.Detect(fragment) {
|
||||||
// need to add 1 since line counting starts at 1
|
// need to add 1 since line counting starts at 1
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package sources
|
package sources
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/fatih/semgroup"
|
"github.com/fatih/semgroup"
|
||||||
"github.com/rs/zerolog/log"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type ScanTarget struct {
|
type ScanTarget struct {
|
||||||
@@ -35,7 +35,12 @@ func DirectoryTargets(source string, s *semgroup.Group, followSymlinks bool) (<-
|
|||||||
Symlink: "",
|
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)
|
realPath, err := filepath.EvalSymlinks(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
Reference in new issue
Block a user