diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2019-04-11 14:15:49 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-11 14:15:49 -0700 |
commit | cb2b019d5debadbe29cba59e93130bd8c562771a (patch) | |
tree | 657ec566995ffdd48f58c045917350ea8a7b5b65 /cmd/podman | |
parent | 272f10f1bbf885c15b7a02175804020d71a5f992 (diff) | |
parent | 034cc8a5aeac5c6df39e7b4b7229f95803159542 (diff) | |
download | podman-cb2b019d5debadbe29cba59e93130bd8c562771a.tar.gz podman-cb2b019d5debadbe29cba59e93130bd8c562771a.tar.bz2 podman-cb2b019d5debadbe29cba59e93130bd8c562771a.zip |
Merge pull request #2885 from kunalkushwaha/image-dangling-filter-fix
imagefilter dangling handling corrected
Diffstat (limited to 'cmd/podman')
-rw-r--r-- | cmd/podman/imagefilters/filters.go | 7 | ||||
-rw-r--r-- | cmd/podman/images.go | 10 |
2 files changed, 14 insertions, 3 deletions
diff --git a/cmd/podman/imagefilters/filters.go b/cmd/podman/imagefilters/filters.go index 2932d61c0..aa5776599 100644 --- a/cmd/podman/imagefilters/filters.go +++ b/cmd/podman/imagefilters/filters.go @@ -37,9 +37,12 @@ func CreatedAfterFilter(createTime time.Time) ResultFilter { } // DanglingFilter allows you to filter images for dangling images -func DanglingFilter() ResultFilter { +func DanglingFilter(danglingImages bool) ResultFilter { return func(i *adapter.ContainerImage) bool { - return i.Dangling() + if danglingImages { + return i.Dangling() + } + return !i.Dangling() } } diff --git a/cmd/podman/images.go b/cmd/podman/images.go index bea27e2ff..c38d7035d 100644 --- a/cmd/podman/images.go +++ b/cmd/podman/images.go @@ -5,6 +5,7 @@ import ( "fmt" "reflect" "sort" + "strconv" "strings" "time" "unicode" @@ -360,6 +361,9 @@ func CreateFilterFuncs(ctx context.Context, r *adapter.LocalRuntime, filters []s var filterFuncs []imagefilters.ResultFilter for _, filter := range filters { splitFilter := strings.Split(filter, "=") + if len(splitFilter) != 2 { + return nil, errors.Errorf("invalid filter syntax %s", filter) + } switch splitFilter[0] { case "before": before, err := r.NewImageFromLocal(splitFilter[1]) @@ -374,7 +378,11 @@ func CreateFilterFuncs(ctx context.Context, r *adapter.LocalRuntime, filters []s } filterFuncs = append(filterFuncs, imagefilters.CreatedAfterFilter(after.Created())) case "dangling": - filterFuncs = append(filterFuncs, imagefilters.DanglingFilter()) + danglingImages, err := strconv.ParseBool(splitFilter[1]) + if err != nil { + return nil, errors.Wrapf(err, "invalid filter dangling=%s", splitFilter[1]) + } + filterFuncs = append(filterFuncs, imagefilters.DanglingFilter(danglingImages)) case "label": labelFilter := strings.Join(splitFilter[1:], "=") filterFuncs = append(filterFuncs, imagefilters.LabelFilter(ctx, labelFilter)) |