summaryrefslogtreecommitdiff
path: root/pkg/util
diff options
context:
space:
mode:
authorCharlie Doern <cdoern@redhat.com>2022-07-11 13:51:45 -0400
committerCharlie Doern <cdoern@redhat.com>2022-07-25 09:28:26 -0400
commit4724a0000d48d372c84057a065e40a1bd298603a (patch)
tree5324e65ee23a9259c8d55d1c366904729856bc18 /pkg/util
parentda1f47921685f40f1b26405278cbf9cb2d06fe09 (diff)
downloadpodman-4724a0000d48d372c84057a065e40a1bd298603a.tar.gz
podman-4724a0000d48d372c84057a065e40a1bd298603a.tar.bz2
podman-4724a0000d48d372c84057a065e40a1bd298603a.zip
prune filter handling
network and container prune could not handle the label!=... filter. vendor in c/common to fix this and add some podman level handling to make everything run smoothly resolves #14182 Signed-off-by: Charlie Doern <cdoern@redhat.com>
Diffstat (limited to 'pkg/util')
-rw-r--r--pkg/util/filters.go33
-rw-r--r--pkg/util/filters_test.go4
2 files changed, 3 insertions, 34 deletions
diff --git a/pkg/util/filters.go b/pkg/util/filters.go
index 08148806f..104b9c3c2 100644
--- a/pkg/util/filters.go
+++ b/pkg/util/filters.go
@@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"net/http"
- "path/filepath"
"strings"
"time"
@@ -94,35 +93,3 @@ func PrepareFilters(r *http.Request) (*map[string][]string, error) {
}
return &filterMap, nil
}
-
-func matchPattern(pattern string, value string) bool {
- if strings.Contains(pattern, "*") {
- filter := fmt.Sprintf("*%s*", pattern)
- filter = strings.ReplaceAll(filter, string(filepath.Separator), "|")
- newName := strings.ReplaceAll(value, string(filepath.Separator), "|")
- match, _ := filepath.Match(filter, newName)
- return match
- }
- return false
-}
-
-// MatchLabelFilters matches labels and returns true if they are valid
-func MatchLabelFilters(filterValues []string, labels map[string]string) bool {
-outer:
- for _, filterValue := range filterValues {
- filterArray := strings.SplitN(filterValue, "=", 2)
- filterKey := filterArray[0]
- if len(filterArray) > 1 {
- filterValue = filterArray[1]
- } else {
- filterValue = ""
- }
- for labelKey, labelValue := range labels {
- if ((labelKey == filterKey) || matchPattern(filterKey, labelKey)) && (filterValue == "" || labelValue == filterValue) {
- continue outer
- }
- }
- return false
- }
- return true
-}
diff --git a/pkg/util/filters_test.go b/pkg/util/filters_test.go
index 47259013e..8e45ea61c 100644
--- a/pkg/util/filters_test.go
+++ b/pkg/util/filters_test.go
@@ -2,6 +2,8 @@ package util
import (
"testing"
+
+ "github.com/containers/common/pkg/filters"
)
func TestMatchLabelFilters(t *testing.T) {
@@ -71,7 +73,7 @@ func TestMatchLabelFilters(t *testing.T) {
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
- if got := MatchLabelFilters(tt.args.filterValues, tt.args.labels); got != tt.want {
+ if got := filters.MatchLabelFilters(tt.args.filterValues, tt.args.labels); got != tt.want {
t.Errorf("MatchLabelFilters() = %v, want %v", got, tt.want)
}
})