Skip to content

Commit 3aa7000

Browse files
committed
fix(db): Ignore missing buckets during cleanup
The cleanup deletes all buckets after a build completes. When building with --only-update for a set of sources, some of the buckets in the overall set are never created because the sources that populate them are skipped. Then cleanup fails with "bucket not found" even though the data update completed. Ignore bolt.ErrBucketNotFound. This is safe to do since a bucket that doesn't exist doesn't have to be cleaned up. Signed-off-by: Prarit Bhargava <prarit@redhat.com>
1 parent 8ffac5a commit 3aa7000

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

pkg/db/db.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ func (dbc Config) forEach(bktNames []string) (map[string]Value, error) {
284284

285285
func (dbc Config) deleteBucket(bucketName string) error {
286286
return db.Update(func(tx *bolt.Tx) error {
287-
if err := tx.DeleteBucket([]byte(bucketName)); err != nil {
287+
err := tx.DeleteBucket([]byte(bucketName))
288+
if err != nil && !errors.Is(err, bolt.ErrBucketNotFound) {
288289
return oops.With("bucket_name", bucketName).Wrapf(err, "failed to delete bucket")
289290
}
290291
return nil

pkg/vulndb/db_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ func TestTrivyDB_Build(t *testing.T) {
179179
"testdata/fixtures/happy/vulnid.yaml",
180180
"testdata/fixtures/happy/vulnerability-detail.yaml",
181181
},
182-
wantErr: "failed to delete advisory detail bucket",
183182
},
184183
}
185184

0 commit comments

Comments
 (0)