@@ -358,6 +358,30 @@ func (e *imageExporterInstance) pushImage(ctx context.Context, src *exporter.Sou
358358}
359359
360360func (e * imageExporterInstance ) unpackImage (ctx context.Context , img images.Image , src * exporter.Source , s session.Group ) (err0 error ) {
361+ p := platforms .Format (platforms .Normalize (platforms .DefaultSpec ()))
362+
363+ ps , err := exptypes .ParsePlatforms (src .Metadata )
364+ if err != nil {
365+ return err
366+ }
367+ found := false
368+ for _ , p2 := range ps .Platforms {
369+ if p2 .ID == p {
370+ found = true
371+ break
372+ }
373+ }
374+ if ! found {
375+ // current platform was not found, so skip unpacking
376+ return nil
377+ }
378+
379+ ref , _ := src .FindRef (p )
380+ if ref == nil {
381+ // ref has no layers, so nothing to unpack
382+ return nil
383+ }
384+
361385 unpackDone := progress .OneOff (ctx , "unpacking to " + img .Name )
362386 defer func () {
363387 unpackDone (err0 )
@@ -375,15 +399,6 @@ func (e *imageExporterInstance) unpackImage(ctx context.Context, img images.Imag
375399 return err
376400 }
377401
378- ref , ok := src .FindRef (defaultPlatform ())
379- if ! ok {
380- return errors .Errorf ("no reference for default platform %s" , defaultPlatform ())
381- }
382- if ref == nil {
383- // ref has no layers, so nothing to unpack
384- return nil
385- }
386-
387402 remotes , err := ref .GetRemotes (ctx , true , e .opts .RefCfg , false , s )
388403 if err != nil {
389404 return err
@@ -457,12 +472,6 @@ func addAnnotations(m map[digest.Digest]map[string]string, desc ocispecs.Descrip
457472 }
458473}
459474
460- func defaultPlatform () string {
461- // Use normalized platform string to avoid the mismatch with platform options which
462- // are normalized using platforms.Normalize()
463- return platforms .Format (platforms .Normalize (platforms .DefaultSpec ()))
464- }
465-
466475func NewDescriptorReference (desc ocispecs.Descriptor , release func (context.Context ) error ) exporter.DescriptorReference {
467476 return & descriptorReference {
468477 desc : desc ,
0 commit comments