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 9f206c4
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 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 @@ -87,11 +88,22 @@ func (g *GrypeAdapter) Ready(ctx context.Context) bool {
logger.L().Info("updating grype DB",
helpers.String("listingURL", g.dbConfig.ListingURL))
var err error
g.store, g.dbStatus, g.dbCloser, err = grype.LoadVulnerabilityDB(g.dbConfig, true)
newStore, newDbStatus, newDbCloser, err := grype.LoadVulnerabilityDB(g.dbConfig, true)
if err != nil {
logger.L().Ctx(ctx).Error("failed to update grype DB", helpers.Error(err))
if g.dbCloser != nil {
g.dbCloser.Close()
logger.L().Debug("closed DB")
}
err := os.RemoveAll(g.dbConfig.DBRootDir)
_ = os.Mkdir(g.dbConfig.DBRootDir, 0755)
logger.L().Debug("cleaned up cache", helpers.Error(err),
helpers.String("DBRootDir", g.dbConfig.DBRootDir))
return false
}
g.store = newStore
g.dbStatus = newDbStatus
g.dbCloser = newDbCloser
g.lastDbUpdate = now
logger.L().Info("grype DB updated")
return true
Expand Down

0 comments on commit 9f206c4

Please sign in to comment.