@@ -241,7 +241,7 @@ func computeBlobChain(ctx context.Context, sr *immutableRef, createIfNeeded bool
241
241
return nil , errors .Errorf ("unknown layer compression type" )
242
242
}
243
243
244
- if err := sr .setBlob (ctx , comp . Type , desc ); err != nil {
244
+ if err := sr .setBlob (ctx , desc ); err != nil {
245
245
return nil , err
246
246
}
247
247
return nil , nil
@@ -267,10 +267,15 @@ func computeBlobChain(ctx context.Context, sr *immutableRef, createIfNeeded bool
267
267
268
268
// setBlob associates a blob with the cache record.
269
269
// A lease must be held for the blob when calling this function
270
- func (sr * immutableRef ) setBlob (ctx context.Context , compressionType compression. Type , desc ocispecs.Descriptor ) error {
270
+ func (sr * immutableRef ) setBlob (ctx context.Context , desc ocispecs.Descriptor ) ( rerr error ) {
271
271
if _ , ok := leases .FromContext (ctx ); ! ok {
272
272
return errors .Errorf ("missing lease requirement for setBlob" )
273
273
}
274
+ defer func () {
275
+ if rerr == nil {
276
+ rerr = sr .linkBlob (ctx , desc )
277
+ }
278
+ }()
274
279
275
280
diffID , err := diffIDFromDescriptor (desc )
276
281
if err != nil {
@@ -280,10 +285,6 @@ func (sr *immutableRef) setBlob(ctx context.Context, compressionType compression
280
285
return err
281
286
}
282
287
283
- if compressionType == compression .UnknownCompression {
284
- return errors .Errorf ("unhandled layer media type: %q" , desc .MediaType )
285
- }
286
-
287
288
sr .mu .Lock ()
288
289
defer sr .mu .Unlock ()
289
290
@@ -311,9 +312,6 @@ func (sr *immutableRef) setBlob(ctx context.Context, compressionType compression
311
312
return err
312
313
}
313
314
314
- if err := sr .addCompressionBlob (ctx , desc , compressionType ); err != nil {
315
- return err
316
- }
317
315
return nil
318
316
}
319
317
@@ -437,11 +435,11 @@ func ensureCompression(ctx context.Context, ref *immutableRef, comp compression.
437
435
// This ref can be used as the specified compressionType. Keep it lazy.
438
436
return nil , nil
439
437
}
440
- return nil , ref .addCompressionBlob (ctx , desc , comp . Type )
438
+ return nil , ref .linkBlob (ctx , desc )
441
439
}
442
440
443
441
// First, lookup local content store
444
- if _ , err := ref .getCompressionBlob (ctx , comp .Type ); err == nil {
442
+ if _ , err := ref .getBlobWithCompression (ctx , comp .Type ); err == nil {
445
443
return nil , nil // found the compression variant. no need to convert.
446
444
}
447
445
@@ -460,7 +458,7 @@ func ensureCompression(ctx context.Context, ref *immutableRef, comp compression.
460
458
}
461
459
462
460
// Start to track converted layer
463
- if err := ref .addCompressionBlob (ctx , * newDesc , comp . Type ); err != nil {
461
+ if err := ref .linkBlob (ctx , * newDesc ); err != nil {
464
462
return nil , errors .Wrapf (err , "failed to add compression blob" )
465
463
}
466
464
return nil , nil
0 commit comments