Skip to content

Commit

Permalink
Merge pull request containers#1503 from vrothberg/fix-podman-18445
Browse files Browse the repository at this point in the history
libimage: fix reference filters
  • Loading branch information
openshift-merge-robot authored Jun 14, 2023
2 parents e1ea4d9 + a146adf commit 93be4a8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
12 changes: 10 additions & 2 deletions libimage/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (r *Runtime) compileImageFilters(ctx context.Context, options *ListImagesOp
filter = filterManifest(ctx, manifest)

case "reference":
filter = filterReferences(value)
filter = filterReferences(r, value)

case "until":
until, err := r.until(value)
Expand Down Expand Up @@ -268,8 +268,15 @@ func filterManifest(ctx context.Context, value bool) filterFunc {
}

// filterReferences creates a reference filter for matching the specified value.
func filterReferences(value string) filterFunc {
func filterReferences(r *Runtime, value string) filterFunc {
lookedUp, _, _ := r.LookupImage(value, nil)
return func(img *Image) (bool, error) {
if lookedUp != nil {
if lookedUp.ID() == img.ID() {
return true, nil
}
}

refs, err := img.NamesReferences()
if err != nil {
return false, err
Expand Down Expand Up @@ -306,6 +313,7 @@ func filterReferences(value string) filterFunc {
}
}
}

return false, nil
}
}
Expand Down
1 change: 1 addition & 0 deletions libimage/filters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func TestFilterReference(t *testing.T) {
{"quay.io/libpod/*", 2},
{"busybox", 1},
{"alpine", 1},
{"alpine@" + alpine.Digest().String(), 1},
} {
listOptions := &ListImagesOptions{
Filters: []string{"reference=" + test.filter},
Expand Down

0 comments on commit 93be4a8

Please sign in to comment.