@@ -349,6 +349,13 @@ func (e *imageExporterInstance) pushImage(ctx context.Context, src *exporter.Sou
349349}
350350
351351func (e * imageExporterInstance ) unpackImage (ctx context.Context , img images.Image , src * exporter.Source , s session.Group ) (err0 error ) {
352+ p := platforms .Normalize (platforms .DefaultSpec ())
353+ ref , ok := src .FindRef (platforms .Format (p ))
354+ if ! ok || ref == nil {
355+ // platform ref not found, or found platform ref has no layers, so nothing to unpack
356+ return nil
357+ }
358+
352359 unpackDone := progress .OneOff (ctx , "unpacking to " + img .Name )
353360 defer func () {
354361 unpackDone (err0 )
@@ -366,15 +373,6 @@ func (e *imageExporterInstance) unpackImage(ctx context.Context, img images.Imag
366373 return err
367374 }
368375
369- ref , ok := src .FindRef (defaultPlatform ())
370- if ! ok {
371- return errors .Errorf ("no reference for default platform %s" , defaultPlatform ())
372- }
373- if ref == nil {
374- // ref has no layers, so nothing to unpack
375- return nil
376- }
377-
378376 remotes , err := ref .GetRemotes (ctx , true , e .opts .RefCfg , false , s )
379377 if err != nil {
380378 return err
@@ -448,12 +446,6 @@ func addAnnotations(m map[digest.Digest]map[string]string, desc ocispecs.Descrip
448446 }
449447}
450448
451- func defaultPlatform () string {
452- // Use normalized platform string to avoid the mismatch with platform options which
453- // are normalized using platforms.Normalize()
454- return platforms .Format (platforms .Normalize (platforms .DefaultSpec ()))
455- }
456-
457449func NewDescriptorReference (desc ocispecs.Descriptor , release func (context.Context ) error ) exporter.DescriptorReference {
458450 return & descriptorReference {
459451 desc : desc ,
0 commit comments