diff options
author | Jakub Guzik <jakubmguzik@gmail.com> | 2021-03-23 00:13:44 +0100 |
---|---|---|
committer | Jakub Guzik <jakubmguzik@gmail.com> | 2021-03-24 00:40:30 +0100 |
commit | 5eab1b07428e4078bd15ca5b69f28f2733850cdd (patch) | |
tree | acc9b0a1f3b726cc117170bbca5ce60e27aa9083 /libpod/image | |
parent | 4d3e71ad28f75b51dc5fa7a29775ce30c9d5c437 (diff) | |
download | podman-5eab1b07428e4078bd15ca5b69f28f2733850cdd.tar.gz podman-5eab1b07428e4078bd15ca5b69f28f2733850cdd.tar.bz2 podman-5eab1b07428e4078bd15ca5b69f28f2733850cdd.zip |
Unification of label filter across list/prune endpoints
Signed-off-by: Jakub Guzik <jakubmguzik@gmail.com>
Diffstat (limited to 'libpod/image')
-rw-r--r-- | libpod/image/filters.go | 14 | ||||
-rw-r--r-- | libpod/image/prune.go | 15 |
2 files changed, 5 insertions, 24 deletions
diff --git a/libpod/image/filters.go b/libpod/image/filters.go index 37d3cb6a5..d316c6956 100644 --- a/libpod/image/filters.go +++ b/libpod/image/filters.go @@ -9,6 +9,7 @@ import ( "time" "github.com/containers/podman/v3/pkg/inspect" + "github.com/containers/podman/v3/pkg/util" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) @@ -78,23 +79,14 @@ func ReadOnlyFilter(readOnly bool) ResultFilter { } // LabelFilter allows you to filter by images labels key and/or value -func LabelFilter(ctx context.Context, labelfilter string) ResultFilter { +func LabelFilter(ctx context.Context, filter string) ResultFilter { // We need to handle both label=key and label=key=value return func(i *Image) bool { - var value string - splitFilter := strings.SplitN(labelfilter, "=", 2) - key := splitFilter[0] - if len(splitFilter) > 1 { - value = splitFilter[1] - } labels, err := i.Labels(ctx) if err != nil { return false } - if len(strings.TrimSpace(labels[key])) > 0 && len(strings.TrimSpace(value)) == 0 { - return true - } - return labels[key] == value + return util.MatchLabelFilters([]string{filter}, labels) } } diff --git a/libpod/image/prune.go b/libpod/image/prune.go index d6ae5feaf..1ab785dd2 100644 --- a/libpod/image/prune.go +++ b/libpod/image/prune.go @@ -8,6 +8,7 @@ import ( "github.com/containers/podman/v3/libpod/events" "github.com/containers/podman/v3/pkg/domain/entities/reports" "github.com/containers/podman/v3/pkg/timetype" + "github.com/containers/podman/v3/pkg/util" "github.com/containers/storage" "github.com/pkg/errors" "github.com/sirupsen/logrus" @@ -16,24 +17,12 @@ import ( func generatePruneFilterFuncs(filter, filterValue string) (ImageFilter, error) { switch filter { case "label": - var filterArray = strings.SplitN(filterValue, "=", 2) - var filterKey = filterArray[0] - if len(filterArray) > 1 { - filterValue = filterArray[1] - } else { - filterValue = "" - } return func(i *Image) bool { labels, err := i.Labels(context.Background()) if err != nil { return false } - for labelKey, labelValue := range labels { - if labelKey == filterKey && (filterValue == "" || labelValue == filterValue) { - return true - } - } - return false + return util.MatchLabelFilters([]string{filterValue}, labels) }, nil case "until": |