@@ -285,19 +285,21 @@ func (d *BoltDBDriver) HasBlob(digest godigest.Digest, blob string) bool {
285285 return zerr .ErrCacheMiss
286286 }
287287
288+ if origin .Get ([]byte (blob )) != nil {
289+ d .log .Debug ().Str ("key" , blob ).Msg ("found in original bucket" )
290+ return nil
291+ }
292+
288293 deduped := bucket .Bucket ([]byte (constants .DuplicatesBucket ))
289294 if deduped == nil {
290295 return zerr .ErrCacheMiss
291296 }
292297
293- if origin .Get ([]byte (blob )) == nil {
294- if deduped .Get ([]byte (blob )) == nil {
295- return zerr .ErrCacheMiss
296- }
297- d .log .Debug ().Str ("key" , blob ).Msg ("found in dedupe bucket" )
298+ if deduped .Get ([]byte (blob )) == nil {
299+ return zerr .ErrCacheMiss
298300 }
299301
300- d .log .Debug ().Str ("key" , blob ).Msg ("found in original bucket" )
302+ d .log .Debug ().Str ("key" , blob ).Msg ("found in duplicates bucket" )
301303
302304 return nil
303305 }); err != nil {
@@ -343,30 +345,34 @@ func (d *BoltDBDriver) DeleteBlob(digest godigest.Digest, path string) error {
343345 return zerr .ErrCacheMiss
344346 }
345347
348+ // look first in the duplicates bucket
346349 deduped := bucket .Bucket ([]byte (constants .DuplicatesBucket ))
347- if deduped == nil {
348- return zerr .ErrCacheMiss
349- }
350-
351- if err := deduped .Delete ([]byte (path )); err != nil {
352- d .log .Error ().Err (err ).Str ("digest" , digest .String ()).Str ("bucket" , constants .DuplicatesBucket ).
353- Str ("path" , path ).Msg ("failed to delete" )
350+ if deduped != nil {
351+ if deduped .Get ([]byte (path )) != nil {
352+ if err := deduped .Delete ([]byte (path )); err != nil {
353+ d .log .Error ().Err (err ).Str ("digest" , digest .String ()).Str ("bucket" , constants .DuplicatesBucket ).
354+ Str ("path" , path ).Msg ("failed to delete" )
354355
355- return err
356- }
356+ return err
357+ }
357358
358- d .log .Debug ().Str ("digest" , digest .String ()).Str ("path" , path ).Msg ("deleted from dedupe bucket" )
359+ d .log .Debug ().Str ("digest" , digest .String ()).Str ("path" , path ).Msg ("deleted from dedupe bucket" )
359360
360- dedupeBlob := d .getOne (deduped )
361- if dedupeBlob != nil {
362- d .log .Debug ().Str ("digest" , digest .String ()).Str ("path" , path ).Msg ("more in dedupe bucket, leaving original alone" )
363- return nil
361+ return nil
362+ }
364363 }
365364
366365 origin := bucket .Bucket ([]byte (constants .OriginalBucket ))
367366 if origin != nil {
368- originBlob := d .getOne (origin )
369- if originBlob != nil {
367+ if origin .Get ([]byte (path )) != nil {
368+
369+ dedupeBlob := d .getOne (deduped )
370+ if dedupeBlob != nil {
371+ d .log .Debug ().Str ("digest" , digest .String ()).Str ("path" , path ).Msg ("more in dedupe bucket, leaving original alone" )
372+
373+ return nil
374+ }
375+
370376 if err := origin .Delete ([]byte (path )); err != nil {
371377 d .log .Error ().Err (err ).Str ("digest" , digest .String ()).Str ("bucket" , constants .OriginalBucket ).
372378 Str ("path" , path ).Msg ("failed to delete" )
@@ -401,9 +407,11 @@ func (d *BoltDBDriver) DeleteBlob(digest godigest.Digest, path string) error {
401407
402408 return err
403409 }
410+
411+ return nil
404412 }
405413
406- return nil
414+ return zerr . ErrCacheMiss
407415 }); err != nil {
408416 return err
409417 }
0 commit comments