diff options
Diffstat (limited to 'cmd/podman')
-rw-r--r-- | cmd/podman/common/completion.go | 4 | ||||
-rw-r--r-- | cmd/podman/common/volumes.go | 4 | ||||
-rw-r--r-- | cmd/podman/containers/cp.go | 8 | ||||
-rw-r--r-- | cmd/podman/login.go | 24 | ||||
-rw-r--r-- | cmd/podman/logout.go | 9 | ||||
-rw-r--r-- | cmd/podman/validate/args.go | 7 |
6 files changed, 42 insertions, 14 deletions
diff --git a/cmd/podman/common/completion.go b/cmd/podman/common/completion.go index c93f2017c..177d094aa 100644 --- a/cmd/podman/common/completion.go +++ b/cmd/podman/common/completion.go @@ -8,11 +8,11 @@ import ( "strings" "github.com/containers/common/pkg/config" + "github.com/containers/image/v5/pkg/sysregistriesv2" "github.com/containers/podman/v3/cmd/podman/registry" "github.com/containers/podman/v3/libpod/define" "github.com/containers/podman/v3/pkg/domain/entities" "github.com/containers/podman/v3/pkg/network" - "github.com/containers/podman/v3/pkg/registries" "github.com/containers/podman/v3/pkg/rootless" systemdDefine "github.com/containers/podman/v3/pkg/systemd/define" "github.com/containers/podman/v3/pkg/util" @@ -236,7 +236,7 @@ func getSecrets(cmd *cobra.Command, toComplete string) ([]string, cobra.ShellCom } func getRegistries() ([]string, cobra.ShellCompDirective) { - regs, err := registries.GetRegistries() + regs, err := sysregistriesv2.UnqualifiedSearchRegistries(nil) if err != nil { cobra.CompErrorln(err.Error()) return nil, cobra.ShellCompDirectiveNoFileComp diff --git a/cmd/podman/common/volumes.go b/cmd/podman/common/volumes.go index aff323936..883d604da 100644 --- a/cmd/podman/common/volumes.go +++ b/cmd/podman/common/volumes.go @@ -337,9 +337,9 @@ func getBindMount(args []string) (spec.Mount, error) { } switch kv[1] { case "private": - newMount.Options = append(newMount.Options, "z") - case "shared": newMount.Options = append(newMount.Options, "Z") + case "shared": + newMount.Options = append(newMount.Options, "z") default: return newMount, errors.Wrapf(util.ErrBadMntOption, "%s mount option must be 'private' or 'shared'", kv[0]) } diff --git a/cmd/podman/containers/cp.go b/cmd/podman/containers/cp.go index 2c7d72b20..0ad258824 100644 --- a/cmd/podman/containers/cp.go +++ b/cmd/podman/containers/cp.go @@ -177,6 +177,10 @@ func copyFromContainer(container string, containerPath string, hostPath string) containerTarget = filepath.Dir(containerTarget) } + if !isStdout && containerInfo.IsDir && !hostInfo.IsDir { + return errors.New("destination must be a directory when copying a directory") + } + reader, writer := io.Pipe() hostCopy := func() error { defer reader.Close() @@ -334,6 +338,10 @@ func copyToContainer(container string, containerPath string, hostPath string) er stdinFile = tmpFile.Name() } + if hostInfo.IsDir && !containerInfo.IsDir { + return errors.New("destination must be a directory when copying a directory") + } + reader, writer := io.Pipe() hostCopy := func() error { defer writer.Close() diff --git a/cmd/podman/login.go b/cmd/podman/login.go index 2101e32e2..a8dadf5cd 100644 --- a/cmd/podman/login.go +++ b/cmd/podman/login.go @@ -9,7 +9,6 @@ import ( "github.com/containers/image/v5/types" "github.com/containers/podman/v3/cmd/podman/common" "github.com/containers/podman/v3/cmd/podman/registry" - "github.com/containers/podman/v3/pkg/registries" "github.com/spf13/cobra" ) @@ -63,12 +62,29 @@ func login(cmd *cobra.Command, args []string) error { skipTLS = types.NewOptionalBool(!loginOptions.tlsVerify) } - sysCtx := types.SystemContext{ + sysCtx := &types.SystemContext{ AuthFilePath: loginOptions.AuthFile, DockerCertPath: loginOptions.CertDir, DockerInsecureSkipTLSVerify: skipTLS, - SystemRegistriesConfPath: registries.SystemRegistriesConfPath(), } + setRegistriesConfPath(sysCtx) loginOptions.GetLoginSet = cmd.Flag("get-login").Changed - return auth.Login(context.Background(), &sysCtx, &loginOptions.LoginOptions, args) + return auth.Login(context.Background(), sysCtx, &loginOptions.LoginOptions, args) +} + +// setRegistriesConfPath sets the registries.conf path for the specified context. +// NOTE: this is a verbatim copy from c/common/libimage which we're not using +// to prevent leaking c/storage into this file. Maybe this should go into c/image? +func setRegistriesConfPath(systemContext *types.SystemContext) { + if systemContext.SystemRegistriesConfPath != "" { + return + } + if envOverride, ok := os.LookupEnv("CONTAINERS_REGISTRIES_CONF"); ok { + systemContext.SystemRegistriesConfPath = envOverride + return + } + if envOverride, ok := os.LookupEnv("REGISTRIES_CONFIG_PATH"); ok { + systemContext.SystemRegistriesConfPath = envOverride + return + } } diff --git a/cmd/podman/logout.go b/cmd/podman/logout.go index 092ad2610..0ee134635 100644 --- a/cmd/podman/logout.go +++ b/cmd/podman/logout.go @@ -8,7 +8,6 @@ import ( "github.com/containers/image/v5/types" "github.com/containers/podman/v3/cmd/podman/common" "github.com/containers/podman/v3/cmd/podman/registry" - "github.com/containers/podman/v3/pkg/registries" "github.com/spf13/cobra" ) @@ -48,9 +47,9 @@ func init() { // Implementation of podman-logout. func logout(cmd *cobra.Command, args []string) error { - sysCtx := types.SystemContext{ - AuthFilePath: logoutOptions.AuthFile, - SystemRegistriesConfPath: registries.SystemRegistriesConfPath(), + sysCtx := &types.SystemContext{ + AuthFilePath: logoutOptions.AuthFile, } - return auth.Logout(&sysCtx, &logoutOptions, args) + setRegistriesConfPath(sysCtx) + return auth.Logout(sysCtx, &logoutOptions, args) } diff --git a/cmd/podman/validate/args.go b/cmd/podman/validate/args.go index c00813369..fc07a6acc 100644 --- a/cmd/podman/validate/args.go +++ b/cmd/podman/validate/args.go @@ -3,6 +3,7 @@ package validate import ( "fmt" "strconv" + "strings" "github.com/containers/podman/v3/cmd/podman/registry" "github.com/pkg/errors" @@ -20,7 +21,11 @@ func NoArgs(cmd *cobra.Command, args []string) error { // SubCommandExists returns an error if no sub command is provided func SubCommandExists(cmd *cobra.Command, args []string) error { if len(args) > 0 { - return errors.Errorf("unrecognized command `%[1]s %[2]s`\nTry '%[1]s --help' for more information.", cmd.CommandPath(), args[0]) + suggestions := cmd.SuggestionsFor(args[0]) + if len(suggestions) == 0 { + return errors.Errorf("unrecognized command `%[1]s %[2]s`\nTry '%[1]s --help' for more information.", cmd.CommandPath(), args[0]) + } + return errors.Errorf("unrecognized command `%[1]s %[2]s`\n\nDid you mean this?\n\t%[3]s\n\nTry '%[1]s --help' for more information.", cmd.CommandPath(), args[0], strings.Join(suggestions, "\n\t")) } return errors.Errorf("missing command '%[1]s COMMAND'\nTry '%[1]s --help' for more information.", cmd.CommandPath()) } |