mirror of
https://github.com/containers/podman.git
synced 2025-10-18 03:33:32 +08:00
FIXME? Introduce imageParts.suspiciousRefNameTagValuesForSearch
Image.MatchRepoTag and findImageInRepoTags do some kind of heuristic search; the motivation and design of both, and how they should deal with digests, is not obvious to me. Instead of figuring that out now, just factor it out into a scary-named method and leave the "tag" value (with its "latest"/"none" value) alone. Similarly, the .registry and .name fields should typically not be used; users should use either hasRegistry or normalized reference types; so, isolate the difficult-to-understand search code, and computation of these values, into this new search-specific helper. Should not change behavior. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
This commit is contained in:
@ -17,6 +17,7 @@ import (
|
||||
// findImageInRepotags takes an imageParts struct and searches images' repotags for
|
||||
// a match on name:tag
|
||||
func findImageInRepotags(search imageParts, images []*Image) (*storage.Image, error) {
|
||||
_, searchName, searchSuspiciousTagValueForSearch := search.suspiciousRefNameTagValuesForSearch()
|
||||
var results []*storage.Image
|
||||
for _, image := range images {
|
||||
for _, name := range image.Names() {
|
||||
@ -25,21 +26,22 @@ func findImageInRepotags(search imageParts, images []*Image) (*storage.Image, er
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if d.name == search.name && d.tag == search.tag {
|
||||
_, dName, dSuspiciousTagValueForSearch := d.suspiciousRefNameTagValuesForSearch()
|
||||
if dName == searchName && dSuspiciousTagValueForSearch == searchSuspiciousTagValueForSearch {
|
||||
results = append(results, image.image)
|
||||
continue
|
||||
}
|
||||
// account for registry:/somedir/image
|
||||
if strings.HasSuffix(d.name, search.name) && d.tag == search.tag {
|
||||
if strings.HasSuffix(dName, searchName) && dSuspiciousTagValueForSearch == searchSuspiciousTagValueForSearch {
|
||||
results = append(results, image.image)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(results) == 0 {
|
||||
return &storage.Image{}, errors.Errorf("unable to find a name and tag match for %s in repotags", search.name)
|
||||
return &storage.Image{}, errors.Errorf("unable to find a name and tag match for %s in repotags", searchName)
|
||||
} else if len(results) > 1 {
|
||||
return &storage.Image{}, errors.Errorf("found multiple name and tag matches for %s in repotags", search.name)
|
||||
return &storage.Image{}, errors.Errorf("found multiple name and tag matches for %s in repotags", searchName)
|
||||
}
|
||||
return results[0], nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user