Skip to content

Commit 9063978

Browse files
committed
image.go: move rename into saveBlobResult method
Signed-off-by: Han-Wen Nienhuys <[email protected]>
1 parent 931e2e6 commit 9063978

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

image.go

+17-5
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,16 @@ type saveBlobResult struct {
417417
compressedSize int64
418418
}
419419

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+
420430
func (i *containerImageRef) saveBlob(what, path string, rc io.ReadCloser) (*saveBlobResult, error) {
421431
defer rc.Close()
422432
srcHasher := digest.Canonical.Digester()
@@ -726,12 +736,14 @@ func (i *containerImageRef) NewImageSource(_ context.Context, _ *types.SystemCon
726736
}
727737
}
728738

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)
734741
}
742+
743+
if err := result.rename(); err != nil {
744+
return nil, err
745+
}
746+
735747
// Add a note in the manifest about the layer. The blobs are identified by their possibly-
736748
// compressed blob digests.
737749
olayerDescriptor := v1.Descriptor{

0 commit comments

Comments
 (0)