mirror of https://github.com/containers/podman.git
rmi doesn't remove all images if an error occurs
Print out the error if unable to remove image due to multiple tags or due to it being used in a container and continue to remove all the other images. Signed-off-by: umohnani8 <umohnani@redhat.com> Closes: #153 Approved by: rhatdan
This commit is contained in:
parent
d43c63aad7
commit
0a2f426ceb
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/projectatomic/libpod/libpod"
|
"github.com/projectatomic/libpod/libpod"
|
||||||
|
@ -49,7 +50,9 @@ func rmiCmd(c *cli.Context) error {
|
||||||
if len(args) > 0 && removeAll {
|
if len(args) > 0 && removeAll {
|
||||||
return errors.Errorf("when using the --all switch, you may not pass any images names or IDs")
|
return errors.Errorf("when using the --all switch, you may not pass any images names or IDs")
|
||||||
}
|
}
|
||||||
|
|
||||||
imagesToDelete := args[:]
|
imagesToDelete := args[:]
|
||||||
|
var lastError error
|
||||||
if removeAll {
|
if removeAll {
|
||||||
localImages, err := runtime.GetImages(&libpod.ImageFilterParams{})
|
localImages, err := runtime.GetImages(&libpod.ImageFilterParams{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -63,13 +66,21 @@ func rmiCmd(c *cli.Context) error {
|
||||||
for _, arg := range imagesToDelete {
|
for _, arg := range imagesToDelete {
|
||||||
image, err := runtime.GetImage(arg)
|
image, err := runtime.GetImage(arg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "could not get image %q", arg)
|
if lastError != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, lastError)
|
||||||
|
}
|
||||||
|
lastError = errors.Wrapf(err, "could not get image %q", arg)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
id, err := runtime.RemoveImage(image, c.Bool("force"))
|
id, err := runtime.RemoveImage(image, c.Bool("force"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "error removing image %q", id)
|
if lastError != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, lastError)
|
||||||
}
|
}
|
||||||
fmt.Printf("%s\n", id)
|
lastError = errors.Wrapf(err, "failed to remove image")
|
||||||
|
} else {
|
||||||
|
fmt.Println(id)
|
||||||
}
|
}
|
||||||
return nil
|
}
|
||||||
|
return lastError
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue