summaryrefslogtreecommitdiff
path: root/cmd/podman/rmi.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-02-25 19:48:47 +0100
committerGitHub <noreply@github.com>2019-02-25 19:48:47 +0100
commitbf3b68b128574d6c2e57863a7e2532b8f6e211e2 (patch)
tree21546b987d872879a372e458798804f2548c3b2c /cmd/podman/rmi.go
parent73cfb9f127b0991c3faac9ff1fafed8d65355e4b (diff)
parentfe4c0c37807f250c8f222bbe7634df13a6da8756 (diff)
downloadpodman-bf3b68b128574d6c2e57863a7e2532b8f6e211e2.tar.gz
podman-bf3b68b128574d6c2e57863a7e2532b8f6e211e2.tar.bz2
podman-bf3b68b128574d6c2e57863a7e2532b8f6e211e2.zip
Merge pull request #2421 from rhatdan/rmi
Change exit code to 1 on podman rmi nosuch image
Diffstat (limited to 'cmd/podman/rmi.go')
-rw-r--r--cmd/podman/rmi.go54
1 files changed, 33 insertions, 21 deletions
diff --git a/cmd/podman/rmi.go b/cmd/podman/rmi.go
index fbaa19336..709ed14e0 100644
--- a/cmd/podman/rmi.go
+++ b/cmd/podman/rmi.go
@@ -5,6 +5,8 @@ import (
"os"
"github.com/containers/libpod/cmd/podman/cliconfig"
+ "github.com/containers/libpod/cmd/podman/varlink"
+ "github.com/containers/libpod/libpod/image"
"github.com/containers/libpod/pkg/adapter"
"github.com/containers/storage"
"github.com/pkg/errors"
@@ -29,6 +31,17 @@ var (
}
)
+func imageNotFound(err error) bool {
+ if errors.Cause(err) == image.ErrNoSuchImage {
+ return true
+ }
+ switch err.(type) {
+ case *iopodman.ImageNotFound:
+ return true
+ }
+ return false
+}
+
func init() {
rmiCommand.Command = _rmiCommand
rmiCommand.SetUsageTemplate(UsageTemplate())
@@ -39,10 +52,8 @@ func init() {
func rmiCmd(c *cliconfig.RmiValues) error {
var (
- lastError error
- deleted bool
- deleteErr error
- msg string
+ lastError error
+ failureCnt int
)
ctx := getContext()
@@ -64,19 +75,21 @@ func rmiCmd(c *cliconfig.RmiValues) error {
images := args[:]
removeImage := func(img *adapter.ContainerImage) {
- deleted = true
- msg, deleteErr = runtime.RemoveImage(ctx, img, c.Force)
- if deleteErr != nil {
- if errors.Cause(deleteErr) == storage.ErrImageUsedByContainer {
+ msg, err := runtime.RemoveImage(ctx, img, c.Force)
+ if err != nil {
+ if errors.Cause(err) == storage.ErrImageUsedByContainer {
fmt.Printf("A container associated with containers/storage, i.e. via Buildah, CRI-O, etc., may be associated with this image: %-12.12s\n", img.ID())
}
+ if !imageNotFound(err) {
+ failureCnt++
+ }
if lastError != nil {
fmt.Fprintln(os.Stderr, lastError)
}
- lastError = deleteErr
- } else {
- fmt.Println(msg)
+ lastError = err
+ return
}
+ fmt.Println(msg)
}
if removeAll {
@@ -121,22 +134,21 @@ func rmiCmd(c *cliconfig.RmiValues) error {
for _, i := range images {
newImage, err := runtime.NewImageFromLocal(i)
if err != nil {
- fmt.Fprintln(os.Stderr, err)
+ if lastError != nil {
+ if !imageNotFound(lastError) {
+ failureCnt++
+ }
+ fmt.Fprintln(os.Stderr, lastError)
+ }
+ lastError = err
continue
}
removeImage(newImage)
}
}
- // If the user calls remove all and there are none, it should not be a
- // non-zero exit
- if !deleted && removeAll {
- return nil
- }
- // the user tries to remove images that do not exist, that should be a
- // non-zero exit
- if !deleted {
- return errors.Errorf("no valid images to delete")
+ if imageNotFound(lastError) && failureCnt == 0 {
+ exitCode = 1
}
return lastError