Skip to content

Commit 1d71866

Browse files
Merge pull request #19 from Checkmarx/cx-shaked-karta-fix-local-resolution
Refactor cleanup logic in containerScanner (AST-106461)
2 parents 4c7a90d + f3b1b31 commit 1d71866

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

pkg/containerResolver/containerScanner.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,10 @@ func cleanup(originalPath string, outputPath string, checkmarxPath string) error
116116
}
117117
}
118118

119-
// Clean up containers folder inside .checkmarx if checkmarxPath is provided
120-
if checkmarxPath != "" {
121-
// checkmarxPath points to .checkmarx/containers, so we delete this directory
122-
cxErr := imagesExtractor.DeleteDirectory(checkmarxPath)
123-
if cxErr != nil {
124-
log.Warn().Err(cxErr).Msg("Could not delete containers directory inside .checkmarx folder")
125-
}
126-
}
119+
// The cleanup of .checkmarx/containers should be handled by the caller after it has
120+
// processed the resolution file.
127121

128-
// Only return error from output directory cleanup, not from .checkmarx cleanup
122+
// Only return error from output directory cleanup
129123
return err
130124
}
131125

pkg/containerResolver/containerScanner_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ func TestResolve(t *testing.T) {
150150
mockImagesExtractor.AssertCalled(t, "ExtractAndMergeImagesFromFiles", sampleFileImages, mock.Anything, mock.Anything)
151151
mockSyftPackagesExtractor.AssertCalled(t, "AnalyzeImagesWithPlatform", mock.Anything, "linux/amd64")
152152
mockImagesExtractor.AssertCalled(t, "SaveObjectToFile", checkmarxPath, expectedResolution)
153+
154+
// Verify that the containers directory still exists after Resolve completes
155+
// This tests the fix for the cleanup bug where the directory was being deleted too early
156+
if _, err := os.Stat(checkmarxPath); os.IsNotExist(err) {
157+
t.Errorf("Expected containers directory to exist after Resolve completes, but it was deleted")
158+
}
153159
})
154160

155161
t.Run("ScanPath Validation failure", func(t *testing.T) {

0 commit comments

Comments
 (0)