@@ -770,6 +770,16 @@ type saveBlobResult struct {
770770 compressedSize int64
771771}
772772
773+ func (r * saveBlobResult ) rename () error {
774+ // Rename the layer so that we can more easily find it by digest later.
775+ finalBlobName := filepath .Join (filepath .Dir (r .path ), r .compressedDigest .String ())
776+ if err := os .Rename (r .path , finalBlobName ); err != nil {
777+ return fmt .Errorf ("storing %s to file while renaming %q to %q: %w" , r .what , r .path , finalBlobName , err )
778+ }
779+ r .path = finalBlobName
780+ return nil
781+ }
782+
773783func (i * containerImageRef ) saveLayerBlob (what , path string , rc io.ReadCloser ) (* saveBlobResult , error ) {
774784 defer rc .Close ()
775785 srcHasher := digest .Canonical .Digester ()
@@ -1052,11 +1062,11 @@ func (i *containerImageRef) NewImageSource(_ context.Context, _ *types.SystemCon
10521062 }
10531063
10541064 logrus .Debugf ("%s size is %d bytes, uncompressed digest %s, possibly-compressed digest %s" , what , result .compressedSize , result .uncompressedDigest .String (), result .compressedDigest .String ())
1055- // Rename the layer so that we can more easily find it by digest later.
1056- finalBlobName := filepath .Join (path , result .compressedDigest .String ())
1057- if err = os .Rename (filepath .Join (path , "layer" ), finalBlobName ); err != nil {
1058- return nil , fmt .Errorf ("storing %s to file while renaming %q to %q: %w" , what , filepath .Join (path , "layer" ), finalBlobName , err )
1065+
1066+ if err := result .rename (); err != nil {
1067+ return nil , err
10591068 }
1069+
10601070 mb .addLayer (result .compressedDigest , result .compressedSize , result .uncompressedDigest )
10611071 }
10621072
0 commit comments