mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-12-01 21:44:23 +01:00
rm comments
This commit is contained in:
1 parent
770baf7458
commit
5f210c9d35
1 file changed
+1
-5
+1
-5
@@ -28,13 +28,11 @@ func IsArchive(path string) bool {
|
|||||||
// ExtractArchive extracts all files from archivePath into a temp dir.
|
// ExtractArchive extracts all files from archivePath into a temp dir.
|
||||||
// Returns the list of ScanTargets (with real file paths) and the temp dir for cleanup.
|
// Returns the list of ScanTargets (with real file paths) and the temp dir for cleanup.
|
||||||
func ExtractArchive(archivePath string) ([]sources.ScanTarget, string, error) {
|
func ExtractArchive(archivePath string) ([]sources.ScanTarget, string, error) {
|
||||||
// 1. Create a temp dir
|
|
||||||
tmpDir, err := os.MkdirTemp("", "gitleaks-archive-")
|
tmpDir, err := os.MkdirTemp("", "gitleaks-archive-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "", err
|
return nil, "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Open the archive
|
|
||||||
f, err := os.Open(archivePath)
|
f, err := os.Open(archivePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.RemoveAll(tmpDir)
|
os.RemoveAll(tmpDir)
|
||||||
@@ -42,7 +40,6 @@ func ExtractArchive(archivePath string) ([]sources.ScanTarget, string, error) {
|
|||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
// 3. Identify format (name-based + header peek)
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
format, stream, err := archives.Identify(ctx, archivePath, f)
|
format, stream, err := archives.Identify(ctx, archivePath, f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -50,14 +47,13 @@ func ExtractArchive(archivePath string) ([]sources.ScanTarget, string, error) {
|
|||||||
return nil, "", err
|
return nil, "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. Ensure it's extractable
|
|
||||||
extractor, ok := format.(archives.Extractor)
|
extractor, ok := format.(archives.Extractor)
|
||||||
if !ok {
|
if !ok {
|
||||||
os.RemoveAll(tmpDir)
|
os.RemoveAll(tmpDir)
|
||||||
return nil, "", fmt.Errorf("format %T is not extractable", format)
|
return nil, "", fmt.Errorf("format %T is not extractable", format)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5. Walk and extract
|
// Walk and extract
|
||||||
var targets []sources.ScanTarget
|
var targets []sources.ScanTarget
|
||||||
err = extractor.Extract(ctx, stream, func(ctx context.Context, file archives.FileInfo) error {
|
err = extractor.Extract(ctx, stream, func(ctx context.Context, file archives.FileInfo) error {
|
||||||
name := file.Name()
|
name := file.Name()
|
||||||
|
|||||||
Reference in new issue
Block a user