diff options
author | Valentin Rothberg <vrothberg@suse.com> | 2018-06-12 14:42:30 +0200 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-06-12 13:38:07 +0000 |
commit | 95ea3d4f3a77d014fdd1be43411ba96a85091712 (patch) | |
tree | 01aaf7f90aa838c7bb62c3f986e8069b5479c806 /cmd | |
parent | ab72130650c7a43421f35b754d51632e3df70966 (diff) | |
download | podman-95ea3d4f3a77d014fdd1be43411ba96a85091712.tar.gz podman-95ea3d4f3a77d014fdd1be43411ba96a85091712.tar.bz2 podman-95ea3d4f3a77d014fdd1be43411ba96a85091712.zip |
rmi: remove image if all tags are specified
Remove the image if all its tags are specified. This didn't work before
as the images have been queried prior to changing them resulting in
inconsistencies regarding repoTags. Now, the images for each specified
tag is loaded one after another to guarantee loading the latest state.
Fixes: #930
Signed-off-by: Valentin Rothberg <vrothberg@suse.com>
Closes: #934
Approved by: rhatdan
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/podman/rmi.go | 50 |
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 } |