mirror of
https://github.com/containers/skopeo.git
synced 2025-09-05 00:31:45 +00:00
warn users about --dest-compress and --dest-decompress misuse
Signed-off-by: Erol Keskin <erolkeskin.dev@gmail.com>
This commit is contained in:
@@ -17,7 +17,6 @@ import (
|
|||||||
"github.com/containers/image/v5/transports/alltransports"
|
"github.com/containers/image/v5/transports/alltransports"
|
||||||
encconfig "github.com/containers/ocicrypt/config"
|
encconfig "github.com/containers/ocicrypt/config"
|
||||||
enchelpers "github.com/containers/ocicrypt/helpers"
|
enchelpers "github.com/containers/ocicrypt/helpers"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -261,14 +260,7 @@ func (opts *copyOptions) run(args []string, stdout io.Writer) (retErr error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if destRef.Transport().Name() != "dir" {
|
opts.destImage.warnAboutIneffectiveOptions(destRef.Transport())
|
||||||
if opts.destImage.dirForceCompression {
|
|
||||||
logrus.Warn("--dest-compress can only be used if the destination transport is 'dir'")
|
|
||||||
}
|
|
||||||
if opts.destImage.dirForceDecompression {
|
|
||||||
logrus.Warn("--dest-decompress can only be used if the destination transport is 'dir'")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return retry.IfNecessary(ctx, func() error {
|
return retry.IfNecessary(ctx, func() error {
|
||||||
manifestBytes, err := copy.Image(ctx, policyContext, destRef, srcRef, ©.Options{
|
manifestBytes, err := copy.Image(ctx, policyContext, destRef, srcRef, ©.Options{
|
||||||
|
@@ -10,6 +10,7 @@ import (
|
|||||||
|
|
||||||
commonFlag "github.com/containers/common/pkg/flag"
|
commonFlag "github.com/containers/common/pkg/flag"
|
||||||
"github.com/containers/common/pkg/retry"
|
"github.com/containers/common/pkg/retry"
|
||||||
|
"github.com/containers/image/v5/directory"
|
||||||
"github.com/containers/image/v5/manifest"
|
"github.com/containers/image/v5/manifest"
|
||||||
"github.com/containers/image/v5/pkg/compression"
|
"github.com/containers/image/v5/pkg/compression"
|
||||||
"github.com/containers/image/v5/transports/alltransports"
|
"github.com/containers/image/v5/transports/alltransports"
|
||||||
@@ -252,12 +253,13 @@ type imageDestOptions struct {
|
|||||||
compressionFormat string // Format to use for the compression
|
compressionFormat string // Format to use for the compression
|
||||||
compressionLevel commonFlag.OptionalInt // Level to use for the compression
|
compressionLevel commonFlag.OptionalInt // Level to use for the compression
|
||||||
precomputeDigests bool // Precompute digests to dedup layers when saving to the docker: transport
|
precomputeDigests bool // Precompute digests to dedup layers when saving to the docker: transport
|
||||||
|
imageDestFlagPrefix string
|
||||||
}
|
}
|
||||||
|
|
||||||
// imageDestFlags prepares a collection of CLI flags writing into imageDestOptions, and the managed imageDestOptions structure.
|
// imageDestFlags prepares a collection of CLI flags writing into imageDestOptions, and the managed imageDestOptions structure.
|
||||||
func imageDestFlags(global *globalOptions, shared *sharedImageOptions, deprecatedTLSVerify *deprecatedTLSVerifyOption, flagPrefix, credsOptionAlias string) (pflag.FlagSet, *imageDestOptions) {
|
func imageDestFlags(global *globalOptions, shared *sharedImageOptions, deprecatedTLSVerify *deprecatedTLSVerifyOption, flagPrefix, credsOptionAlias string) (pflag.FlagSet, *imageDestOptions) {
|
||||||
genericFlags, genericOptions := imageFlags(global, shared, deprecatedTLSVerify, flagPrefix, credsOptionAlias)
|
genericFlags, genericOptions := imageFlags(global, shared, deprecatedTLSVerify, flagPrefix, credsOptionAlias)
|
||||||
opts := imageDestOptions{imageOptions: genericOptions}
|
opts := imageDestOptions{imageOptions: genericOptions, imageDestFlagPrefix: flagPrefix}
|
||||||
fs := pflag.FlagSet{}
|
fs := pflag.FlagSet{}
|
||||||
fs.AddFlagSet(&genericFlags)
|
fs.AddFlagSet(&genericFlags)
|
||||||
fs.BoolVar(&opts.dirForceCompression, flagPrefix+"compress", false, "Compress tarball image layers when saving to directory using the 'dir' transport. (default is same compression type as source)")
|
fs.BoolVar(&opts.dirForceCompression, flagPrefix+"compress", false, "Compress tarball image layers when saving to directory using the 'dir' transport. (default is same compression type as source)")
|
||||||
@@ -295,6 +297,17 @@ func (opts *imageDestOptions) newSystemContext() (*types.SystemContext, error) {
|
|||||||
return ctx, err
|
return ctx, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (opts *imageDestOptions) warnAboutIneffectiveOptions(destTransport types.ImageTransport) {
|
||||||
|
if destTransport.Name() != directory.Transport.Name() {
|
||||||
|
if opts.dirForceCompression {
|
||||||
|
logrus.Warnf("--%s can only be used if the destination transport is 'dir'", opts.imageDestFlagPrefix+"compress")
|
||||||
|
}
|
||||||
|
if opts.dirForceDecompression {
|
||||||
|
logrus.Warnf("--%s can only be used if the destination transport is 'dir'", opts.imageDestFlagPrefix+"decompress")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func parseCreds(creds string) (string, string, error) {
|
func parseCreds(creds string) (string, string, error) {
|
||||||
if creds == "" {
|
if creds == "" {
|
||||||
return "", "", errors.New("credentials can't be empty")
|
return "", "", errors.New("credentials can't be empty")
|
||||||
|
Reference in New Issue
Block a user