Skip to content

Commit

Permalink
try to clean up cache if updating grypeDB fails
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
  • Loading branch information
matthyx committed Jul 13, 2023
1 parent 3c1acf1 commit 94a04f3
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion adapters/v1/grype.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v1

import (
"context"
"os"
"path"
"sync"
"time"
Expand Down Expand Up @@ -89,7 +90,9 @@ func (g *GrypeAdapter) Ready(ctx context.Context) bool {
var err error
g.store, g.dbStatus, g.dbCloser, err = grype.LoadVulnerabilityDB(g.dbConfig, true)
if err != nil {
logger.L().Ctx(ctx).Error("failed to update grype DB", helpers.Error(err))
logger.L().Ctx(ctx).Error("failed to update grype DB, cleaning up cache", helpers.Error(err), helpers.String("DBRootDir", g.dbConfig.DBRootDir))
err := os.RemoveAll(g.dbConfig.DBRootDir)
logger.L().Ctx(ctx).Error("cleaned up cache", helpers.Error(err), helpers.String("DBRootDir", g.dbConfig.DBRootDir))
return false
}
g.lastDbUpdate = now
Expand Down

0 comments on commit 94a04f3

Please sign in to comment.