mirror of
https://github.com/containers/podman.git
synced 2025-08-06 11:32:07 +08:00
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>
This commit is contained in:
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user