Skip to content

Commit

Permalink
Optimize useLayerInfosForCopy a bit
Browse files Browse the repository at this point in the history
Only call ic.src.LayerInfos() if necessary to
evaluate UpdatedLayerInfosForCopy().

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
  • Loading branch information
mtrmac committed Aug 23, 2021
1 parent 9a0cf6d commit 912da56
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions copy/copy.go
Expand Up @@ -819,26 +819,31 @@ func isTTY(w io.Writer) bool {
// useLayerInfosForCopy implements LayerInfosForCopy, if necessary.
// It may modify/replace ic.src.
func (ic *imageCopier) useLayerInfosForCopy(ctx context.Context) error {
srcInfos := ic.src.LayerInfos()
updatedSrcInfos, err := ic.src.LayerInfosForCopy(ctx)
if err != nil {
return err
}
if updatedSrcInfos != nil && !reflect.DeepEqual(srcInfos, updatedSrcInfos) {
if !ic.canModifyManifest {
return errors.Errorf("Copying this image requires changing layer representation, which is not possible (image is signed or the destination specifies a digest)")
}
updates := *ic.manifestUpdates // A shallow copy
updates.LayerInfos = updatedSrcInfos
// We don’t set options.InformationOnly.LayerInfos and options.InformationOnly.LayerDiffIDs,
// because (we don’t have that information, and) the current update implementations don’t need that
// when we are not converting the manifest format.
img, err := updatedImageWithMIME(ctx, ic.src, updates)
if err != nil {
return errors.Wrapf(err, "Error preparing an internally-modified image manifest")
}
ic.src = img
if updatedSrcInfos == nil {
return nil
}
srcInfos := ic.src.LayerInfos()
if reflect.DeepEqual(srcInfos, updatedSrcInfos) {
return nil
}

if !ic.canModifyManifest {
return errors.Errorf("Copying this image requires changing layer representation, which is not possible (image is signed or the destination specifies a digest)")
}
updates := *ic.manifestUpdates // A shallow copy
updates.LayerInfos = updatedSrcInfos
// We don’t set options.InformationOnly.LayerInfos and options.InformationOnly.LayerDiffIDs,
// because (we don’t have that information, and) the current update implementations don’t need that
// when we are not converting the manifest format.
img, err := updatedImageWithMIME(ctx, ic.src, updates)
if err != nil {
return errors.Wrapf(err, "Error preparing an internally-modified image manifest")
}
ic.src = img
return nil
}

Expand Down

0 comments on commit 912da56

Please sign in to comment.