Skip to content

Commit

Permalink
Merge pull request #1294 from moio/allow-decompression
Browse files Browse the repository at this point in the history
Add support for decompressing while copying to dir://
  • Loading branch information
mtrmac authored Jul 27, 2021
2 parents e20a890 + e3f0cac commit 91e9af4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
26 changes: 18 additions & 8 deletions directory/directory_dest.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,26 @@ const version = "Directory Transport Version: 1.1\n"
var ErrNotContainerImageDir = errors.New("not a containers image directory, don't want to overwrite important data")

type dirImageDestination struct {
ref dirReference
compress bool
ref dirReference
desiredLayerCompression types.LayerCompression
}

// newImageDestination returns an ImageDestination for writing to a directory.
func newImageDestination(ref dirReference, compress bool) (types.ImageDestination, error) {
d := &dirImageDestination{ref: ref, compress: compress}
func newImageDestination(sys *types.SystemContext, ref dirReference) (types.ImageDestination, error) {
desiredLayerCompression := types.PreserveOriginal
if sys != nil {
if sys.DirForceCompress {
desiredLayerCompression = types.Compress

if sys.DirForceDecompress {
return nil, errors.Errorf("Cannot compress and decompress at the same time")
}
}
if sys.DirForceDecompress {
desiredLayerCompression = types.Decompress
}
}
d := &dirImageDestination{ref: ref, desiredLayerCompression: desiredLayerCompression}

// If directory exists check if it is empty
// if not empty, check whether the contents match that of a container image directory and overwrite the contents
Expand Down Expand Up @@ -101,10 +114,7 @@ func (d *dirImageDestination) SupportsSignatures(ctx context.Context) error {
}

func (d *dirImageDestination) DesiredLayerCompression() types.LayerCompression {
if d.compress {
return types.Compress
}
return types.PreserveOriginal
return d.desiredLayerCompression
}

// AcceptsForeignLayerURLs returns false iff foreign layers in manifest should be actually
Expand Down
6 changes: 1 addition & 5 deletions directory/directory_transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,7 @@ func (ref dirReference) NewImageSource(ctx context.Context, sys *types.SystemCon
// NewImageDestination returns a types.ImageDestination for this reference.
// The caller must call .Close() on the returned ImageDestination.
func (ref dirReference) NewImageDestination(ctx context.Context, sys *types.SystemContext) (types.ImageDestination, error) {
compress := false
if sys != nil {
compress = sys.DirForceCompress
}
return newImageDestination(ref, compress)
return newImageDestination(sys, ref)
}

// DeleteImage deletes the named image from the registry, if supported.
Expand Down
2 changes: 2 additions & 0 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,8 @@ type SystemContext struct {
// === dir.Transport overrides ===
// DirForceCompress compresses the image layers if set to true
DirForceCompress bool
// DirForceDecompress decompresses the image layers if set to true
DirForceDecompress bool

// CompressionFormat is the format to use for the compression of the blobs
CompressionFormat *compression.Algorithm
Expand Down

0 comments on commit 91e9af4

Please sign in to comment.