Skip to content

Commit

Permalink
Merge pull request #1883 from flouthoc/refactor-copy-multiple-images
Browse files Browse the repository at this point in the history
copy/multiple: use more flexible `EditInstances` instead of `UpdateInstances`
  • Loading branch information
mtrmac authored Jun 3, 2023
2 parents 32e1469 + b70f961 commit f5f7ac8
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 f5f7ac8

Please sign in to comment.