Skip to content

Commit 772f744

Browse files
Merge branch 'main' into feature/alex-update-new-container-resolver
2 parents af3f570 + 2fc507b commit 772f744

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

internal/commands/scan.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2622,19 +2622,19 @@ func cleanUpTempZip(zipFilePath string) {
26222622
if zipFilePath != "" {
26232623
logger.PrintIfVerbose("Cleaning up temporary zip: " + zipFilePath)
26242624
tries := cleanupMaxRetries
2625-
for tries > 0 {
2625+
for attempt := 1; tries > 0; attempt++ {
26262626
zipRemoveErr := os.Remove(zipFilePath)
26272627
if zipRemoveErr != nil {
26282628
logger.PrintIfVerbose(
26292629
fmt.Sprintf(
2630-
"Failed to remove temporary zip: %d in %d: %v",
2631-
cleanupMaxRetries-tries,
2630+
"Failed to remove temporary zip: Attempt %d/%d: %v",
2631+
attempt,
26322632
cleanupMaxRetries,
26332633
zipRemoveErr,
26342634
),
26352635
)
26362636
tries--
2637-
time.Sleep(time.Duration(cleanupRetryWaitSeconds) * time.Second)
2637+
Wait(attempt)
26382638
} else {
26392639
logger.PrintIfVerbose("Removed temporary zip")
26402640
break
@@ -2648,6 +2648,13 @@ func cleanUpTempZip(zipFilePath string) {
26482648
}
26492649
}
26502650

2651+
func Wait(attempt int) {
2652+
// Calculate exponential backoff delay
2653+
waitDuration := time.Duration(cleanupRetryWaitSeconds * (1 << (attempt - 1))) // 2^(attempt-1)
2654+
logger.PrintIfVerbose(fmt.Sprintf("Waiting %d seconds before retrying...", waitDuration))
2655+
time.Sleep(waitDuration * time.Second)
2656+
}
2657+
26512658
func deprecatedFlagValue(cmd *cobra.Command, deprecatedFlagKey, inUseFlagKey string) string {
26522659
flagValue, _ := cmd.Flags().GetString(inUseFlagKey)
26532660
if flagValue == "" {

0 commit comments

Comments
 (0)