From b6c76f6bf2fa143da8bdcc4698a78463fb2e66e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B4mulo=20Farias?= Date: Tue, 13 Aug 2024 14:58:16 +0200 Subject: [PATCH] Clean 'scan cache clean' code and add timeout to it --- internal/vulnerability/runner.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/internal/vulnerability/runner.go b/internal/vulnerability/runner.go index 7d742b637a..8436b88862 100644 --- a/internal/vulnerability/runner.go +++ b/internal/vulnerability/runner.go @@ -19,7 +19,6 @@ package vulnerability import ( "context" - "errors" "time" "github.com/aquasecurity/trivy/pkg/commands/artifact" @@ -86,12 +85,12 @@ func clearTrivyCache(ctx context.Context, log *logp.Logger) error { log.Info("Starting VulnerabilityRunner.ClearCache") defer log.Info("Ending VulnerabilityRunner.ClearCache") - err := clean.Run(ctx, flag.Options{CleanOptions: flag.CleanOptions{CleanScanCache: true}}) - if err != nil { - if !errors.Is(err, artifact.SkipScan) { - return err - } - } - - return nil + return clean.Run(ctx, flag.Options{ + CleanOptions: flag.CleanOptions{ + CleanScanCache: true, + }, + GlobalOptions: flag.GlobalOptions{ + Timeout: 5 * time.Second, + }, + }) }