Skip to content

Commit

Permalink
copy/multiple: use EditInstances instead of UpdateInstance
Browse files Browse the repository at this point in the history
After #1896 `c/image` now
supports new API `EditInstances` which is more flexible in terms of
`Adding` new instances or `Modifying` exisiting instances so lets use
that.

Signed-off-by: Aditya R <[email protected]>
  • Loading branch information
flouthoc committed Jun 3, 2023
1 parent 32e1469 commit b70f961
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions copy/multiple.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,12 @@ func (c *copier) copyMultipleImages(ctx context.Context, policyContext *signatur
imagesToCopy = len(options.Instances)
}
c.Printf("Copying %d of %d images in list\n", imagesToCopy, len(instanceDigests))
updates := make([]manifest.ListUpdate, len(instanceDigests))
instanceEdits := []internalManifest.ListEdit{}
instancesCopied := 0
for i, instanceDigest := range instanceDigests {
if options.ImageListSelection == CopySpecificImages &&
!slices.Contains(options.Instances, instanceDigest) {
update, err := updatedList.Instance(instanceDigest)
if err != nil {
return nil, err
}
logrus.Debugf("Skipping instance %s (%d/%d)", instanceDigest, i+1, len(instanceDigests))
// Record the digest/size/type of the manifest that we didn't copy.
updates[i] = update
continue
}
logrus.Debugf("Copying instance %s (%d/%d)", instanceDigest, i+1, len(instanceDigests))
Expand All @@ -116,16 +110,16 @@ func (c *copier) copyMultipleImages(ctx context.Context, policyContext *signatur
}
instancesCopied++
// Record the result of a possible conversion here.
update := manifest.ListUpdate{
Digest: updatedManifestDigest,
Size: int64(len(updatedManifest)),
MediaType: updatedManifestType,
}
updates[i] = update
instanceEdits = append(instanceEdits, internalManifest.ListEdit{
ListOperation: internalManifest.ListOpUpdate,
UpdateOldDigest: instanceDigest,
UpdateDigest: updatedManifestDigest,
UpdateSize: int64(len(updatedManifest)),
UpdateMediaType: updatedManifestType})
}

// Now reset the digest/size/types of the manifests in the list to account for any conversions that we made.
if err = updatedList.UpdateInstances(updates); err != nil {
if err = updatedList.EditInstances(instanceEdits); err != nil {
return nil, fmt.Errorf("updating manifest list: %w", err)
}

Expand Down

0 comments on commit b70f961

Please sign in to comment.