forked from containers/podman
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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: containers#2192 Signed-off-by: baude <[email protected]> MH: Removed dependence on remote-client adapter work to limit scale of changes Signed-off-by: Matthew Heon <[email protected]>
- Loading branch information
Showing
8 changed files
with
76 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2453,6 +2453,8 @@ _podman_images_prune() { | |
" | ||
|
||
local boolean_options=" | ||
-a | ||
--all | ||
-h | ||
--help | ||
" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,47 @@ | ||
package image | ||
|
||
import "github.com/pkg/errors" | ||
|
||
// GetPruneImages returns a slice of images that have no names/unused | ||
func (ir *Runtime) GetPruneImages() ([]*Image, error) { | ||
func (ir *Runtime) GetPruneImages(all bool) ([]*Image, error) { | ||
var ( | ||
unamedImages []*Image | ||
pruneImages []*Image | ||
) | ||
allImages, err := ir.GetImages() | ||
if err != nil { | ||
return nil, err | ||
} | ||
for _, i := range allImages { | ||
if len(i.Names()) == 0 { | ||
unamedImages = append(unamedImages, i) | ||
pruneImages = append(pruneImages, i) | ||
continue | ||
} | ||
containers, err := i.Containers() | ||
if err != nil { | ||
return nil, err | ||
if all { | ||
containers, err := i.Containers() | ||
if err != nil { | ||
return nil, err | ||
} | ||
if len(containers) < 1 { | ||
pruneImages = append(pruneImages, i) | ||
} | ||
} | ||
if len(containers) < 1 { | ||
unamedImages = append(unamedImages, i) | ||
} | ||
return pruneImages, nil | ||
} | ||
|
||
// PruneImages prunes dangling and optionally all unused images from the local | ||
// image store | ||
func (ir *Runtime) PruneImages(all bool) ([]string, error) { | ||
var prunedCids []string | ||
pruneImages, err := ir.GetPruneImages(all) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "unable to get images to prune") | ||
} | ||
for _, p := range pruneImages { | ||
if err := p.Remove(true); err != nil { | ||
return nil, errors.Wrap(err, "failed to prune image") | ||
} | ||
prunedCids = append(prunedCids, p.ID()) | ||
} | ||
return unamedImages, nil | ||
return prunedCids, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters