summaryrefslogtreecommitdiff
path: root/cmd/podman/rm.go
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2019-02-24 19:04:39 -0500
committerDaniel J Walsh <dwalsh@redhat.com>2019-02-25 10:31:04 -0500
commite41279b902a334e53c56330a28f42d7a6027df74 (patch)
tree1c74f918827bec245e8c136f832aab8a34186cda /cmd/podman/rm.go
parent9e70411ffc24732049e133c83873f7834edf7c0a (diff)
downloadpodman-e41279b902a334e53c56330a28f42d7a6027df74.tar.gz
podman-e41279b902a334e53c56330a28f42d7a6027df74.tar.bz2
podman-e41279b902a334e53c56330a28f42d7a6027df74.zip
Change exit code to 1 on podman rm nosuch container
Make it easy for scripts to determine if a container removal fails versus the container did not exist. If only errors were no such container exit with 1 versus 125. Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'cmd/podman/rm.go')
-rw-r--r--cmd/podman/rm.go20
1 files changed, 19 insertions, 1 deletions
diff --git a/cmd/podman/rm.go b/cmd/podman/rm.go
index 01ed70f52..2dcb491d7 100644
--- a/cmd/podman/rm.go
+++ b/cmd/podman/rm.go
@@ -7,6 +7,7 @@ import (
"github.com/containers/libpod/cmd/podman/libpodruntime"
"github.com/containers/libpod/cmd/podman/shared"
"github.com/containers/libpod/libpod"
+ "github.com/containers/libpod/libpod/image"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
@@ -61,15 +62,21 @@ func rmCmd(c *cliconfig.RmValues) error {
}
defer runtime.Shutdown(false)
+ failureCnt := 0
delContainers, err := getAllOrLatestContainers(&c.PodmanCommand, runtime, -1, "all")
if err != nil {
if c.Force && len(c.InputArgs) > 0 {
if errors.Cause(err) == libpod.ErrNoSuchCtr {
err = nil
+ } else {
+ failureCnt++
}
runtime.RemoveContainersFromStorage(c.InputArgs)
}
if len(delContainers) == 0 {
+ if err != nil && failureCnt == 0 {
+ exitCode = 1
+ }
return err
}
if err != nil {
@@ -96,5 +103,16 @@ func rmCmd(c *cliconfig.RmValues) error {
// Run the parallel funcs
deleteErrors, errCount := shared.ParallelExecuteWorkerPool(maxWorkers, deleteFuncs)
- return printParallelOutput(deleteErrors, errCount)
+ err = printParallelOutput(deleteErrors, errCount)
+ if err != nil {
+ for _, result := range deleteErrors {
+ if result != nil && errors.Cause(result) != image.ErrNoSuchCtr {
+ failureCnt++
+ }
+ }
+ if failureCnt == 0 {
+ exitCode = 1
+ }
+ }
+ return err
}