Skip to content

Commit 71f5678

Browse files
fix(storage): only promote dedupe origin when the deleted blob is the origin (boltdb) (#4201)
Signed-off-by: Artem Muterko <artem@sopho.tech>
1 parent 4425477 commit 71f5678

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

pkg/storage/cache/boltdb.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ func (d *BoltDBDriver) DeleteBlob(digest godigest.Digest, path string) error {
345345
origin := bucket.Bucket([]byte(constants.OriginalBucket))
346346
if origin != nil {
347347
originBlob := d.getOne(origin)
348-
if originBlob != nil {
348+
if originBlob != nil && string(originBlob) == path {
349349
if err := origin.Delete([]byte(path)); err != nil {
350350
d.log.Error().Err(err).Str("digest", digest.String()).Str("bucket", constants.OriginalBucket).
351351
Str("path", path).Msg("failed to delete")

pkg/storage/cache/boltdb_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,35 @@ func TestBoltDBCache(t *testing.T) {
166166
So(blobs, ShouldResemble, []string{"second"})
167167
})
168168
}
169+
170+
func TestBoltDBDeleteNonOriginDuplicate(t *testing.T) {
171+
Convey("Deleting a non-origin duplicate must not promote another path to origin", t, func() {
172+
dir := t.TempDir()
173+
174+
log := log.NewTestLogger()
175+
So(log, ShouldNotBeNil)
176+
177+
cacheDriver, _ := storage.Create("boltdb", cache.BoltDBDriverParameters{dir, "cache_test", false}, log)
178+
So(cacheDriver, ShouldNotBeNil)
179+
180+
err := cacheDriver.PutBlob("digest", "zebra")
181+
So(err, ShouldBeNil)
182+
183+
err = cacheDriver.PutBlob("digest", "alpha")
184+
So(err, ShouldBeNil)
185+
186+
err = cacheDriver.PutBlob("digest", "mango")
187+
So(err, ShouldBeNil)
188+
189+
val, err := cacheDriver.GetBlob("digest")
190+
So(err, ShouldBeNil)
191+
So(val, ShouldEqual, "zebra")
192+
193+
err = cacheDriver.DeleteBlob("digest", "mango")
194+
So(err, ShouldBeNil)
195+
196+
val, err = cacheDriver.GetBlob("digest")
197+
So(err, ShouldBeNil)
198+
So(val, ShouldEqual, "zebra")
199+
})
200+
}

0 commit comments

Comments
 (0)