@@ -417,6 +417,16 @@ type saveBlobResult struct {
417
417
compressedSize int64
418
418
}
419
419
420
+ func (r * saveBlobResult ) rename () error {
421
+ dest := filepath .Join (filepath .Dir (r .path ), r .compressedDigest .String ())
422
+ if err := os .Rename (r .path , dest ); err != nil {
423
+ return fmt .Errorf ("storing %s to file while renaming %q to %q: %w" , r .what , r .path , dest , err )
424
+ }
425
+
426
+ r .path = dest
427
+ return nil
428
+ }
429
+
420
430
func (i * containerImageRef ) saveBlob (what , path string , rc io.ReadCloser ) (* saveBlobResult , error ) {
421
431
defer rc .Close ()
422
432
srcHasher := digest .Canonical .Digester ()
@@ -726,12 +736,14 @@ func (i *containerImageRef) NewImageSource(_ context.Context, _ *types.SystemCon
726
736
}
727
737
}
728
738
729
- logrus .Debugf ("%s size is %d bytes, uncompressed digest %s, possibly-compressed digest %s" , what , result .uncompressedSize , result .uncompressedDigest .String (), result .compressedDigest .String ())
730
- // Rename the layer so that we can more easily find it by digest later.
731
- finalBlobName := filepath .Join (path , result .compressedDigest .String ())
732
- if err = os .Rename (filepath .Join (path , "layer" ), finalBlobName ); err != nil {
733
- return nil , fmt .Errorf ("storing %s to file while renaming %q to %q: %w" , what , filepath .Join (path , "layer" ), finalBlobName , err )
739
+ if err != nil {
740
+ return nil , fmt .Errorf ("storing %s to file: %w" , what , err )
734
741
}
742
+
743
+ if err := result .rename (); err != nil {
744
+ return nil , err
745
+ }
746
+
735
747
// Add a note in the manifest about the layer. The blobs are identified by their possibly-
736
748
// compressed blob digests.
737
749
olayerDescriptor := v1.Descriptor {
0 commit comments