mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-29 20:54:22 +01:00
one tmp dir to rule them all, I think
This commit is contained in:
1 parent
56e409d9f1
commit
e0ea9cefde
7 files changed
+58
-41
No files matched your search
+15
-21
@@ -36,8 +36,17 @@ const (
|
||||
var (
|
||||
newLineRegexp = regexp.MustCompile("\n")
|
||||
isWindows = runtime.GOOS == "windows"
|
||||
tmpDir string
|
||||
)
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
tmpDir, err = os.MkdirTemp("", "gitleaks-*")
|
||||
if err != nil {
|
||||
logging.Fatal().Err(err).Msg("failed to create temp dir for archive extraction")
|
||||
}
|
||||
}
|
||||
|
||||
// Detector is the main detector struct
|
||||
type Detector struct {
|
||||
// Config is the configuration for the detector
|
||||
@@ -102,27 +111,12 @@ type Detector struct {
|
||||
TotalBytes atomic.Uint64
|
||||
}
|
||||
|
||||
// Fragment contains the data to be scanned
|
||||
type Fragment struct {
|
||||
// Raw is the raw content of the fragment
|
||||
Raw string
|
||||
|
||||
Bytes []byte
|
||||
|
||||
// FilePath is the path to the file, if applicable.
|
||||
// The path separator MUST be normalized to `/`.
|
||||
FilePath string
|
||||
SymlinkFile string
|
||||
// WindowsFilePath is the path with the original separator.
|
||||
// This provides a backwards-compatible solution to https://github.com/gitleaks/gitleaks/issues/1565.
|
||||
WindowsFilePath string `json:"-"` // TODO: remove this in v9.
|
||||
|
||||
// CommitSHA is the SHA of the commit if applicable
|
||||
CommitSHA string
|
||||
|
||||
// newlineIndices is a list of indices of newlines in the raw content.
|
||||
// This is used to calculate the line location of a finding
|
||||
newlineIndices [][]int
|
||||
func (d *Detector) Cleanup() {
|
||||
if tmpDir != "" {
|
||||
if err := os.RemoveAll(tmpDir); err != nil {
|
||||
logging.Warn().Err(err).Msg("failed to remove temp dir for archive extraction")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// NewDetector creates a new detector with the given config
|
||||
|
||||
Reference in new issue
Block a user