aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2021-01-18 14:49:53 -0500
committerDaniel J Walsh <dwalsh@redhat.com>2021-01-20 07:37:13 -0500
commite7df73efadd36e2489954ee9a766a3fbfe4eafeb (patch)
tree4d27e452a26e4b6d6f942c80da75940ee57d5582 /cmd
parent7d024a2fc8c675e4d34e3b34b56b6217a48ef9ce (diff)
downloadpodman-e7df73efadd36e2489954ee9a766a3fbfe4eafeb.tar.gz
podman-e7df73efadd36e2489954ee9a766a3fbfe4eafeb.tar.bz2
podman-e7df73efadd36e2489954ee9a766a3fbfe4eafeb.zip
Fix handling of container remove
I found several problems with container remove podman-remote rm --all Was not handled podman-remote rm --ignore Was not handled Return better errors when attempting to remove an --external container. Currently we return the container does not exists, as opposed to container is an external container that is being used. This patch also consolidates the tunnel code to use the same code for removing the container, as the local API, removing duplication of code and potential problems. Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/containers/rm.go15
1 files changed, 13 insertions, 2 deletions
diff --git a/cmd/podman/containers/rm.go b/cmd/podman/containers/rm.go
index ee9dc4c78..ea616b6e5 100644
--- a/cmd/podman/containers/rm.go
+++ b/cmd/podman/containers/rm.go
@@ -3,6 +3,7 @@ package containers
import (
"context"
"fmt"
+ "io/ioutil"
"strings"
"github.com/containers/common/pkg/completion"
@@ -54,6 +55,7 @@ var (
var (
rmOptions = entities.RmOptions{}
+ cidFiles = []string{}
)
func rmFlags(cmd *cobra.Command) {
@@ -65,7 +67,7 @@ func rmFlags(cmd *cobra.Command) {
flags.BoolVarP(&rmOptions.Volumes, "volumes", "v", false, "Remove anonymous volumes associated with the container")
cidfileFlagName := "cidfile"
- flags.StringArrayVarP(&rmOptions.CIDFiles, cidfileFlagName, "", nil, "Read the container ID from the file")
+ flags.StringArrayVar(&cidFiles, cidfileFlagName, nil, "Read the container ID from the file")
_ = cmd.RegisterFlagCompletionFunc(cidfileFlagName, completion.AutocompleteDefault)
if !registry.IsRemote() {
@@ -92,7 +94,16 @@ func init() {
validate.AddLatestFlag(containerRmCommand, &rmOptions.Latest)
}
-func rm(_ *cobra.Command, args []string) error {
+func rm(cmd *cobra.Command, args []string) error {
+ for _, cidFile := range cidFiles {
+ content, err := ioutil.ReadFile(string(cidFile))
+ if err != nil {
+ return errors.Wrap(err, "error reading CIDFile")
+ }
+ id := strings.Split(string(content), "\n")[0]
+ args = append(args, id)
+ }
+
return removeContainers(args, rmOptions, true)
}