Skip to content

Commit

Permalink
copy/single: add custom compressionFormat, compressionLevel fields
Browse files Browse the repository at this point in the history
After containers#2048 there is no room for copy/multiple to pass custom compressionFormat to copySingleImage
while processing each instance, following PR introduces that functionality again and wraps options
to simpler struct.

Signed-off-by: Aditya R <arajan@redhat.com>
  • Loading branch information
flouthoc committed Aug 4, 2023
1 parent 63deaa7 commit 6272732
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
6 changes: 2 additions & 4 deletions copy/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,7 @@ func Image(ctx context.Context, policyContext *signature.PolicyContext, destRef,

if !multiImage {
// The simple case: just copy a single image.
singleImageOpts := copySingleImageOptions{requireCompressionFormatMatch: false}
single, err := c.copySingleImage(ctx, c.unparsedToplevel, nil, singleImageOpts)
single, err := c.copySingleImage(ctx, c.unparsedToplevel, nil, copySingleImageOptions{requireCompressionFormatMatch: false})
if err != nil {
return nil, err
}
Expand All @@ -274,8 +273,7 @@ func Image(ctx context.Context, policyContext *signature.PolicyContext, destRef,
}
logrus.Debugf("Source is a manifest list; copying (only) instance %s for current system", instanceDigest)
unparsedInstance := image.UnparsedInstance(rawSource, &instanceDigest)
singleImageOpts := copySingleImageOptions{requireCompressionFormatMatch: false}
single, err := c.copySingleImage(ctx, unparsedInstance, nil, singleImageOpts)
single, err := c.copySingleImage(ctx, unparsedInstance, nil, copySingleImageOptions{requireCompressionFormatMatch: false})
if err != nil {
return nil, fmt.Errorf("copying system image from manifest list: %w", err)
}
Expand Down
3 changes: 1 addition & 2 deletions copy/multiple.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ func (c *copier) copyMultipleImages(ctx context.Context) (copiedManifest []byte,
logrus.Debugf("Copying instance %s (%d/%d)", instance.sourceDigest, i+1, len(instanceCopyList))
c.Printf("Copying image %s (%d/%d)\n", instance.sourceDigest, i+1, len(instanceCopyList))
unparsedInstance := image.UnparsedInstance(c.rawSource, &instanceCopyList[i].sourceDigest)
singleImageOpts := copySingleImageOptions{requireCompressionFormatMatch: false}
updated, err := c.copySingleImage(ctx, unparsedInstance, &instanceCopyList[i].sourceDigest, singleImageOpts)
updated, err := c.copySingleImage(ctx, unparsedInstance, &instanceCopyList[i].sourceDigest, copySingleImageOptions{requireCompressionFormatMatch: false})
if err != nil {
return nil, fmt.Errorf("copying image %d/%d from manifest list: %w", i+1, len(instanceCopyList), err)
}
Expand Down
6 changes: 4 additions & 2 deletions copy/single.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ type imageCopier struct {

type copySingleImageOptions struct {
requireCompressionFormatMatch bool
compressionFormat *compressiontypes.Algorithm // Compression algorithm to use, if the user explicitly requested one, or nil.
compressionLevel *int
}

// copySingleImageResult carries data produced by copySingleImage
Expand Down Expand Up @@ -139,8 +141,8 @@ func (c *copier) copySingleImage(ctx context.Context, unparsedImage *image.Unpar
}
if c.options.DestinationCtx != nil {
// Note that compressionFormat and compressionLevel can be nil.
ic.compressionFormat = c.options.DestinationCtx.CompressionFormat
ic.compressionLevel = c.options.DestinationCtx.CompressionLevel
ic.compressionFormat = opts.compressionFormat
ic.compressionLevel = opts.compressionLevel
}
// Decide whether we can substitute blobs with semantic equivalents:
// - Don’t do that if we can’t modify the manifest at all
Expand Down

0 comments on commit 6272732

Please sign in to comment.