diff --git a/pkg/containerResolver/containerScanner.go b/pkg/containerResolver/containerScanner.go index 415ef74..5bb73e2 100644 --- a/pkg/containerResolver/containerScanner.go +++ b/pkg/containerResolver/containerScanner.go @@ -116,16 +116,10 @@ func cleanup(originalPath string, outputPath string, checkmarxPath string) error } } - // Clean up containers folder inside .checkmarx if checkmarxPath is provided - if checkmarxPath != "" { - // checkmarxPath points to .checkmarx/containers, so we delete this directory - cxErr := imagesExtractor.DeleteDirectory(checkmarxPath) - if cxErr != nil { - log.Warn().Err(cxErr).Msg("Could not delete containers directory inside .checkmarx folder") - } - } + // The cleanup of .checkmarx/containers should be handled by the caller after it has + // processed the resolution file. - // Only return error from output directory cleanup, not from .checkmarx cleanup + // Only return error from output directory cleanup return err } diff --git a/pkg/containerResolver/containerScanner_test.go b/pkg/containerResolver/containerScanner_test.go index 893145c..96e25ff 100644 --- a/pkg/containerResolver/containerScanner_test.go +++ b/pkg/containerResolver/containerScanner_test.go @@ -150,6 +150,12 @@ func TestResolve(t *testing.T) { mockImagesExtractor.AssertCalled(t, "ExtractAndMergeImagesFromFiles", sampleFileImages, mock.Anything, mock.Anything) mockSyftPackagesExtractor.AssertCalled(t, "AnalyzeImagesWithPlatform", mock.Anything, "linux/amd64") mockImagesExtractor.AssertCalled(t, "SaveObjectToFile", checkmarxPath, expectedResolution) + + // Verify that the containers directory still exists after Resolve completes + // This tests the fix for the cleanup bug where the directory was being deleted too early + if _, err := os.Stat(checkmarxPath); os.IsNotExist(err) { + t.Errorf("Expected containers directory to exist after Resolve completes, but it was deleted") + } }) t.Run("ScanPath Validation failure", func(t *testing.T) {