@@ -709,27 +709,31 @@ func runSingleScan(ctx context.Context, cmd string, cfg engine.Config) (metrics,
709
709
}
710
710
eng .Start (ctx )
711
711
712
- tmpFile := filepath .Join (os .TempDir (), "truffle-temp-repo" )
712
+ tmpDir := filepath .Join (os .TempDir (), "trufflehog_" + strconv .Itoa (os .Getpid ()))
713
+ // We need to persist the repo(s) if we're using legacy JSON output
714
+ // because it requires commit SHAs in the output.
715
+ persistRepo := * gitNoCleanup || * githubNoCleanup || * gitlabNoCleanup
716
+ if * jsonLegacy && ! persistRepo {
717
+ if err := os .MkdirAll (tmpDir , os .ModePerm ); err != nil {
718
+ return scanMetrics , fmt .Errorf ("failed to create temporary directory: %v" , err )
719
+ }
720
+ * gitNoCleanup , * githubNoCleanup , * gitlabNoCleanup = true , true , true
721
+ * gitClonePath , * githubClonePath , * gitlabClonePath = tmpDir , tmpDir , tmpDir
722
+ }
723
+
713
724
defer func () {
714
725
// Clean up temporary artifacts.
715
726
if err := cleantemp .CleanTempArtifacts (ctx ); err != nil {
716
727
ctx .Logger ().Error (err , "error cleaning temp artifacts" )
717
728
}
718
729
719
- if err := os .RemoveAll (tmpFile ); err != nil {
720
- ctx .Logger ().Error (err , "error removing temporary directory" )
730
+ if ! persistRepo {
731
+ if err := os .RemoveAll (tmpDir ); err != nil {
732
+ ctx .Logger ().Error (err , "error removing temporary directory" )
733
+ }
721
734
}
722
735
}()
723
736
724
- persistRepo := * gitNoCleanup || * githubNoCleanup || * gitlabNoCleanup
725
- if * jsonLegacy && ! persistRepo {
726
- if err := os .MkdirAll (tmpFile , os .ModePerm ); err != nil {
727
- return scanMetrics , fmt .Errorf ("failed to create temporary directory: %v" , err )
728
- }
729
- * gitNoCleanup , * githubNoCleanup , * gitlabNoCleanup = true , true , true
730
- * gitClonePath , * githubClonePath , * gitlabClonePath = tmpFile , tmpFile , tmpFile
731
- }
732
-
733
737
var refs []sources.JobProgressRef
734
738
switch cmd {
735
739
case gitScan .FullCommand ():
0 commit comments