summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/podman/rmi.go50
1 files changed, 32 insertions, 18 deletions
diff --git a/cmd/podman/rmi.go b/cmd/podman/rmi.go
index 97c5b38cf..796ec2a3d 100644
--- a/cmd/podman/rmi.go
+++ b/cmd/podman/rmi.go
@@ -56,39 +56,53 @@ func rmiCmd(c *cli.Context) error {
images := args[:]
var lastError error
- var imagesToDelete []*image.Image
+ var deleted bool
+
+ removeImage := func(img *image.Image) {
+ deleted = true
+ msg, err := runtime.RemoveImage(ctx, img, c.Bool("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 lastError != nil {
+ fmt.Fprintln(os.Stderr, lastError)
+ }
+ lastError = err
+ } else {
+ fmt.Println(msg)
+ }
+ }
+
if removeAll {
+ var imagesToDelete []*image.Image
imagesToDelete, err = runtime.ImageRuntime().GetImages()
if err != nil {
return errors.Wrapf(err, "unable to query local images")
}
+ for _, i := range imagesToDelete {
+ removeImage(i)
+ }
} else {
- // Create image.image objects for deletion from user input
+ // Create image.image objects for deletion from user input.
+ // Note that we have to query the storage one-by-one to
+ // always get the latest state for each image. Otherwise, we
+ // run inconsistency issues, for instance, with repoTags.
+ // See https://github.com/projectatomic/libpod/issues/930 as
+ // an exemplary inconsistency issue.
for _, i := range images {
newImage, err := runtime.ImageRuntime().NewFromLocal(i)
if err != nil {
fmt.Fprintln(os.Stderr, err)
continue
}
- imagesToDelete = append(imagesToDelete, newImage)
+ removeImage(newImage)
}
}
- if len(imagesToDelete) == 0 {
+
+ if !deleted {
return errors.Errorf("no valid images to delete")
}
- for _, img := range imagesToDelete {
- msg, err := runtime.RemoveImage(ctx, img, c.Bool("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 lastError != nil {
- fmt.Fprintln(os.Stderr, lastError)
- }
- lastError = err
- } else {
- fmt.Println(msg)
- }
- }
+
return lastError
}