diff options
author | baude <bbaude@redhat.com> | 2019-01-22 09:17:34 -0600 |
---|---|---|
committer | Matthew Heon <matthew.heon@pm.me> | 2019-02-08 15:02:28 -0500 |
commit | 431459caf946c1645da31b4fc6c953ad77f9bc85 (patch) | |
tree | 77ecef4eff5b8e4252a4bbc5f70a56bfa4882958 /cmd/podman/images_prune.go | |
parent | 28f5d25e8dabb6647699c2ccab8621cefac37d3b (diff) | |
download | podman-431459caf946c1645da31b4fc6c953ad77f9bc85.tar.gz podman-431459caf946c1645da31b4fc6c953ad77f9bc85.tar.bz2 podman-431459caf946c1645da31b4fc6c953ad77f9bc85.zip |
podman image prune -- implement all flag
we now, by default, only prune dangling images. if --all is passed, we
prune dangling images AND images that do not have an associated containers.
also went ahead and enabled the podman-remote image prune side of things.
Fixes: #2192
Signed-off-by: baude <bbaude@redhat.com>
MH: Removed dependence on remote-client adapter work to limit scale of changes
Signed-off-by: Matthew Heon <matthew.heon@pm.me>
Diffstat (limited to 'cmd/podman/images_prune.go')
-rw-r--r-- | cmd/podman/images_prune.go | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/cmd/podman/images_prune.go b/cmd/podman/images_prune.go index 06879e02d..7310137e7 100644 --- a/cmd/podman/images_prune.go +++ b/cmd/podman/images_prune.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "github.com/containers/libpod/cmd/podman/libpodruntime" "github.com/pkg/errors" "github.com/urfave/cli" @@ -13,13 +14,19 @@ var ( Removes all unnamed images from local storage ` - + pruneImageFlags = []cli.Flag{ + cli.BoolFlag{ + Name: "all, a", + Usage: "remove all unused images, not just dangling ones", + }, + } pruneImagesCommand = cli.Command{ Name: "prune", Usage: "Remove unused images", Description: pruneImagesDescription, Action: pruneImagesCmd, OnUsageError: usageErrorHandler, + Flags: pruneImageFlags, } ) @@ -30,16 +37,13 @@ func pruneImagesCmd(c *cli.Context) error { } defer runtime.Shutdown(false) - pruneImages, err := runtime.ImageRuntime().GetPruneImages() - if err != nil { - return err - } - - for _, i := range pruneImages { - if err := i.Remove(true); err != nil { - return errors.Wrapf(err, "failed to remove %s", i.ID()) + // Call prune; if any cids are returned, print them and then + // return err in case an error also came up + pruneCids, err := runtime.ImageRuntime().PruneImages(c.Bool("all")) + if len(pruneCids) > 0 { + for _, cid := range pruneCids { + fmt.Println(cid) } - fmt.Println(i.ID()) } - return nil + return err } |