diff --git a/internal/commands/scan.go b/internal/commands/scan.go index 70e8c6654..bb09bdd0f 100644 --- a/internal/commands/scan.go +++ b/internal/commands/scan.go @@ -2622,19 +2622,19 @@ func cleanUpTempZip(zipFilePath string) { if zipFilePath != "" { logger.PrintIfVerbose("Cleaning up temporary zip: " + zipFilePath) tries := cleanupMaxRetries - for tries > 0 { + for attempt := 1; tries > 0; attempt++ { zipRemoveErr := os.Remove(zipFilePath) if zipRemoveErr != nil { logger.PrintIfVerbose( fmt.Sprintf( - "Failed to remove temporary zip: %d in %d: %v", - cleanupMaxRetries-tries, + "Failed to remove temporary zip: Attempt %d/%d: %v", + attempt, cleanupMaxRetries, zipRemoveErr, ), ) tries-- - time.Sleep(time.Duration(cleanupRetryWaitSeconds) * time.Second) + Wait(attempt) } else { logger.PrintIfVerbose("Removed temporary zip") break @@ -2648,6 +2648,13 @@ func cleanUpTempZip(zipFilePath string) { } } +func Wait(attempt int) { + // Calculate exponential backoff delay + waitDuration := time.Duration(cleanupRetryWaitSeconds * (1 << (attempt - 1))) // 2^(attempt-1) + logger.PrintIfVerbose(fmt.Sprintf("Waiting %d seconds before retrying...", waitDuration)) + time.Sleep(waitDuration * time.Second) +} + func deprecatedFlagValue(cmd *cobra.Command, deprecatedFlagKey, inUseFlagKey string) string { flagValue, _ := cmd.Flags().GetString(inUseFlagKey) if flagValue == "" {