mirror of
https://github.com/containers/podman.git
synced 2025-06-23 18:59:30 +08:00
Merge pull request #2423 from rhatdan/rm
Change exit code to 1 on podman rm nosuch container
This commit is contained in:
@ -7,6 +7,7 @@ import (
|
|||||||
"github.com/containers/libpod/cmd/podman/libpodruntime"
|
"github.com/containers/libpod/cmd/podman/libpodruntime"
|
||||||
"github.com/containers/libpod/cmd/podman/shared"
|
"github.com/containers/libpod/cmd/podman/shared"
|
||||||
"github.com/containers/libpod/libpod"
|
"github.com/containers/libpod/libpod"
|
||||||
|
"github.com/containers/libpod/libpod/image"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -61,15 +62,21 @@ func rmCmd(c *cliconfig.RmValues) error {
|
|||||||
}
|
}
|
||||||
defer runtime.Shutdown(false)
|
defer runtime.Shutdown(false)
|
||||||
|
|
||||||
|
failureCnt := 0
|
||||||
delContainers, err := getAllOrLatestContainers(&c.PodmanCommand, runtime, -1, "all")
|
delContainers, err := getAllOrLatestContainers(&c.PodmanCommand, runtime, -1, "all")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if c.Force && len(c.InputArgs) > 0 {
|
if c.Force && len(c.InputArgs) > 0 {
|
||||||
if errors.Cause(err) == libpod.ErrNoSuchCtr {
|
if errors.Cause(err) == libpod.ErrNoSuchCtr {
|
||||||
err = nil
|
err = nil
|
||||||
|
} else {
|
||||||
|
failureCnt++
|
||||||
}
|
}
|
||||||
runtime.RemoveContainersFromStorage(c.InputArgs)
|
runtime.RemoveContainersFromStorage(c.InputArgs)
|
||||||
}
|
}
|
||||||
if len(delContainers) == 0 {
|
if len(delContainers) == 0 {
|
||||||
|
if err != nil && failureCnt == 0 {
|
||||||
|
exitCode = 1
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -96,5 +103,16 @@ func rmCmd(c *cliconfig.RmValues) error {
|
|||||||
|
|
||||||
// Run the parallel funcs
|
// Run the parallel funcs
|
||||||
deleteErrors, errCount := shared.ParallelExecuteWorkerPool(maxWorkers, deleteFuncs)
|
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
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
% podman-rm(1)
|
% podman-container-rm(1)
|
||||||
|
|
||||||
## NAME
|
## NAME
|
||||||
podman\-rm - Remove one or more containers
|
podman\-container\-rm (podman\-rm) - Remove one or more containers
|
||||||
|
|
||||||
## SYNOPSIS
|
## SYNOPSIS
|
||||||
|
**podman container rm** [*options*] *container*
|
||||||
|
|
||||||
**podman rm** [*options*] *container*
|
**podman rm** [*options*] *container*
|
||||||
|
|
||||||
## DESCRIPTION
|
## DESCRIPTION
|
||||||
@ -57,8 +59,13 @@ Forcibly remove the latest container created.
|
|||||||
podman rm -f --latest
|
podman rm -f --latest
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Exit Status
|
||||||
|
**_0_** if all specified containers removed
|
||||||
|
**_1_** if one of the specified containers did not exist, and no other failures
|
||||||
|
**_125_** if command fails for a reason other then an container did not exist
|
||||||
|
|
||||||
## SEE ALSO
|
## SEE ALSO
|
||||||
podman(1), podman-rmi(1)
|
podman(1), podman-image-rm(1)
|
||||||
|
|
||||||
## HISTORY
|
## HISTORY
|
||||||
August 2017, Originally compiled by Ryan Cole <rycole@redhat.com>
|
August 2017, Originally compiled by Ryan Cole <rycole@redhat.com>
|
||||||
|
@ -128,4 +128,9 @@ var _ = Describe("Podman rm", func() {
|
|||||||
Expect(podmanTest.NumberOfContainers()).To(Equal(1))
|
Expect(podmanTest.NumberOfContainers()).To(Equal(1))
|
||||||
|
|
||||||
})
|
})
|
||||||
|
It("podman rm bogus container", func() {
|
||||||
|
session := podmanTest.Podman([]string{"rm", "bogus"})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session.ExitCode()).To(Equal(1))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user