mirror of
https://github.com/containers/podman.git
synced 2025-09-26 08:14:14 +08:00
vendor c/common@main
Update the `--filter reference=...` tests to reflect recent changes in c/common. The reference values now match as specified without implicitly adding wildcards arounds. Fixes: #11905 Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
This commit is contained in:
56
vendor/github.com/containers/common/libimage/filters.go
generated
vendored
56
vendor/github.com/containers/common/libimage/filters.go
generated
vendored
@ -3,13 +3,14 @@ package libimage
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
filtersPkg "github.com/containers/common/pkg/filters"
|
||||
"github.com/containers/common/pkg/timetype"
|
||||
"github.com/containers/image/v5/docker/reference"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
@ -136,7 +137,7 @@ func (r *Runtime) compileImageFilters(ctx context.Context, options *ListImagesOp
|
||||
filterFuncs = append(filterFuncs, filterReadOnly(readOnly))
|
||||
|
||||
case "reference":
|
||||
filterFuncs = append(filterFuncs, filterReference(value))
|
||||
filterFuncs = append(filterFuncs, filterReferences(value))
|
||||
|
||||
case "until":
|
||||
ts, err := timetype.GetTimestamp(value, time.Now())
|
||||
@ -158,24 +159,43 @@ func (r *Runtime) compileImageFilters(ctx context.Context, options *ListImagesOp
|
||||
return filterFuncs, nil
|
||||
}
|
||||
|
||||
// filterReference creates a reference filter for matching the specified value.
|
||||
func filterReference(value string) filterFunc {
|
||||
// Replacing all '/' with '|' so that filepath.Match() can work '|'
|
||||
// character is not valid in image name, so this is safe.
|
||||
//
|
||||
// TODO: this has been copied from Podman and requires some more review
|
||||
// and especially tests.
|
||||
filter := fmt.Sprintf("*%s*", value)
|
||||
filter = strings.ReplaceAll(filter, "/", "|")
|
||||
// filterReferences creates a reference filter for matching the specified value.
|
||||
func filterReferences(value string) filterFunc {
|
||||
return func(img *Image) (bool, error) {
|
||||
if len(value) < 1 {
|
||||
return true, nil
|
||||
refs, err := img.NamesReferences()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
for _, name := range img.Names() {
|
||||
newName := strings.ReplaceAll(name, "/", "|")
|
||||
match, _ := filepath.Match(filter, newName)
|
||||
if match {
|
||||
return true, nil
|
||||
|
||||
for _, ref := range refs {
|
||||
refString := ref.String() // FQN with tag/digest
|
||||
candidates := []string{refString}
|
||||
|
||||
// Split the reference into 3 components (twice if diggested/tagged):
|
||||
// 1) Fully-qualified reference
|
||||
// 2) Without domain
|
||||
// 3) Without domain and path
|
||||
if named, isNamed := ref.(reference.Named); isNamed {
|
||||
candidates = append(candidates,
|
||||
reference.Path(named), // path/name without tag/digest (Path() removes it)
|
||||
refString[strings.LastIndex(refString, "/")+1:]) // name with tag/digest
|
||||
|
||||
trimmedString := reference.TrimNamed(named).String()
|
||||
if refString != trimmedString {
|
||||
tagOrDigest := refString[len(trimmedString):]
|
||||
candidates = append(candidates,
|
||||
trimmedString, // FQN without tag/digest
|
||||
reference.Path(named)+tagOrDigest, // path/name with tag/digest
|
||||
trimmedString[strings.LastIndex(trimmedString, "/")+1:]) // name without tag/digest
|
||||
}
|
||||
}
|
||||
|
||||
for _, candidate := range candidates {
|
||||
// path.Match() is also used by Docker's reference.FamiliarMatch().
|
||||
matched, _ := path.Match(value, candidate)
|
||||
if matched {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return false, nil
|
||||
|
20
vendor/github.com/containers/common/libimage/image.go
generated
vendored
20
vendor/github.com/containers/common/libimage/image.go
generated
vendored
@ -44,6 +44,8 @@ type Image struct {
|
||||
completeInspectData *ImageData
|
||||
// Corresponding OCI image.
|
||||
ociv1Image *ociv1.Image
|
||||
// Names() parsed into references.
|
||||
namesReferences []reference.Reference
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,6 +61,7 @@ func (i *Image) reload() error {
|
||||
i.cached.partialInspectData = nil
|
||||
i.cached.completeInspectData = nil
|
||||
i.cached.ociv1Image = nil
|
||||
i.cached.namesReferences = nil
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -89,6 +92,23 @@ func (i *Image) Names() []string {
|
||||
return i.storageImage.Names
|
||||
}
|
||||
|
||||
// NamesReferences returns Names() as references.
|
||||
func (i *Image) NamesReferences() ([]reference.Reference, error) {
|
||||
if i.cached.namesReferences != nil {
|
||||
return i.cached.namesReferences, nil
|
||||
}
|
||||
refs := make([]reference.Reference, 0, len(i.Names()))
|
||||
for _, name := range i.Names() {
|
||||
ref, err := reference.Parse(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
refs = append(refs, ref)
|
||||
}
|
||||
i.cached.namesReferences = refs
|
||||
return refs, nil
|
||||
}
|
||||
|
||||
// StorageImage returns the underlying storage.Image.
|
||||
func (i *Image) StorageImage() *storage.Image {
|
||||
return i.storageImage
|
||||
|
Reference in New Issue
Block a user