@@ -17,11 +17,11 @@ import (
17
17
dockerArchiveTransport "github.com/containers/image/v5/docker/archive"
18
18
dockerDaemonTransport "github.com/containers/image/v5/docker/daemon"
19
19
"github.com/containers/image/v5/docker/reference"
20
- "github.com/containers/image/v5/manifest"
21
20
ociArchiveTransport "github.com/containers/image/v5/oci/archive"
22
21
ociTransport "github.com/containers/image/v5/oci/layout"
23
22
"github.com/containers/image/v5/pkg/shortnames"
24
23
storageTransport "github.com/containers/image/v5/storage"
24
+ "github.com/containers/image/v5/transports"
25
25
"github.com/containers/image/v5/transports/alltransports"
26
26
"github.com/containers/image/v5/types"
27
27
"github.com/containers/storage"
@@ -230,7 +230,7 @@ func nameFromAnnotations(annotations map[string]string) string {
230
230
// copyFromDefault is the default copier for a number of transports. Other
231
231
// transports require some specific dancing, sometimes Yoga.
232
232
func (r * Runtime ) copyFromDefault (ctx context.Context , ref types.ImageReference , options * CopyOptions ) ([]string , error ) {
233
- c , err := r .newCopier (options )
233
+ c , err := r .newCopier (options , nil )
234
234
if err != nil {
235
235
return nil , err
236
236
}
@@ -386,7 +386,7 @@ func (r *Runtime) copyFromDockerArchive(ctx context.Context, ref types.ImageRefe
386
386
387
387
// copyFromDockerArchiveReaderReference copies the specified readerRef from reader.
388
388
func (r * Runtime ) copyFromDockerArchiveReaderReference (ctx context.Context , reader * dockerArchiveTransport.Reader , readerRef types.ImageReference , options * CopyOptions ) ([]string , error ) {
389
- c , err := r .newCopier (options )
389
+ c , err := r .newCopier (options , nil )
390
390
if err != nil {
391
391
return nil , err
392
392
}
@@ -456,40 +456,6 @@ func (r *Runtime) copyFromRegistry(ctx context.Context, ref types.ImageReference
456
456
return pulledIDs , nil
457
457
}
458
458
459
- // imageIDForPulledImage makes a best-effort guess at an image ID for
460
- // a just-pulled image written to destName, where the pull returned manifestBytes
461
- func (r * Runtime ) imageIDForPulledImage (destName reference.Named , manifestBytes []byte ) (string , error ) {
462
- // The caller, copySingleImageFromRegistry, never triggers a multi-platform copy, so manifestBytes
463
- // is always a single-platform manifest instance.
464
- manifestDigest , err := manifest .Digest (manifestBytes )
465
- if err != nil {
466
- return "" , err
467
- }
468
- destDigestedName , err := reference .WithDigest (reference .TrimNamed (destName ), manifestDigest )
469
- if err != nil {
470
- return "" , err
471
- }
472
- storeRef , err := storageTransport .Transport .NewStoreReference (r .store , destDigestedName , "" )
473
- if err != nil {
474
- return "" , err
475
- }
476
- // With zstd:chunked partial pulls, the same image can have several
477
- // different IDs, depending on which layers of the image were pulled using the
478
- // partial pull (are identified by TOC, not by uncompressed digest).
479
- //
480
- // At this point, from just the manifest digest, we can’t tell which image
481
- // is the one that was actually pulled. (They should all have the same contents
482
- // unless the image author is malicious.)
483
- //
484
- // FIXME: To return an accurate value, c/image would need to return the image ID,
485
- // not just manifestBytes.
486
- _ , image , err := storageTransport .ResolveReference (storeRef )
487
- if err != nil {
488
- return "" , fmt .Errorf ("looking up a just-pulled image: %w" , err )
489
- }
490
- return image .ID , nil
491
- }
492
-
493
459
// copySingleImageFromRegistry pulls the specified, possibly unqualified, name
494
460
// from a registry. On successful pull it returns the ID of the image in local
495
461
// storage (or, FIXME, a name/ID? that could be resolved in local storage)
@@ -632,7 +598,8 @@ func (r *Runtime) copySingleImageFromRegistry(ctx context.Context, imageName str
632
598
if socketPath , ok := os .LookupEnv ("NOTIFY_SOCKET" ); ok {
633
599
options .extendTimeoutSocket = socketPath
634
600
}
635
- c , err := r .newCopier (& options .CopyOptions )
601
+ var resolvedReference types.ImageReference
602
+ c , err := r .newCopier (& options .CopyOptions , & resolvedReference )
636
603
if err != nil {
637
604
return "" , err
638
605
}
@@ -673,8 +640,7 @@ func (r *Runtime) copySingleImageFromRegistry(ctx context.Context, imageName str
673
640
return "" , err
674
641
}
675
642
}
676
- var manifestBytes []byte
677
- if manifestBytes , err = c .Copy (ctx , srcRef , destRef ); err != nil {
643
+ if _ , err := c .Copy (ctx , srcRef , destRef ); err != nil {
678
644
logrus .Debugf ("Error pulling candidate %s: %v" , candidateString , err )
679
645
pullErrors = append (pullErrors , err )
680
646
continue
@@ -687,11 +653,14 @@ func (r *Runtime) copySingleImageFromRegistry(ctx context.Context, imageName str
687
653
}
688
654
689
655
logrus .Debugf ("Pulled candidate %s successfully" , candidateString )
690
- ids , err := r .imageIDForPulledImage (candidate .Value , manifestBytes )
656
+ if resolvedReference == nil { // resolvedReference should always be set for storageTransport destinations
657
+ return "" , fmt .Errorf ("internal error: After pulling %s, resolvedReference is nil" , candidateString )
658
+ }
659
+ _ , image , err := storageTransport .ResolveReference (resolvedReference )
691
660
if err != nil {
692
- return "" , err
661
+ return "" , fmt . Errorf ( "resolving an already-resolved reference %q to the pulled image: %w" , transports . ImageName ( resolvedReference ), err )
693
662
}
694
- return ids , nil
663
+ return image . ID , nil
695
664
}
696
665
697
666
if localImage != nil && pullPolicy == config .PullPolicyNewer {
0 commit comments