summaryrefslogtreecommitdiff
path: root/libpod/image/utils.go
diff options
context:
space:
mode:
Diffstat (limited to 'libpod/image/utils.go')
-rw-r--r--libpod/image/utils.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/libpod/image/utils.go b/libpod/image/utils.go
new file mode 100644
index 000000000..f312c8e4d
--- /dev/null
+++ b/libpod/image/utils.go
@@ -0,0 +1,42 @@
+package image
+
+import (
+ "github.com/containers/image/docker/reference"
+ "github.com/containers/storage"
+ "github.com/pkg/errors"
+)
+
+func getTags(nameInput string) (reference.NamedTagged, bool, error) {
+ inputRef, err := reference.Parse(nameInput)
+ if err != nil {
+ return nil, false, errors.Wrapf(err, "unable to obtain tag from input name")
+ }
+ tagged, isTagged := inputRef.(reference.NamedTagged)
+
+ return tagged, isTagged, nil
+}
+
+// findImageInRepotags takes an imageParts struct and searches images' repotags for
+// a match on name:tag
+func findImageInRepotags(search imageParts, images []*storage.Image) (*storage.Image, error) {
+ var results []*storage.Image
+ for _, image := range images {
+ for _, name := range image.Names {
+ d, err := decompose(name)
+ // if we get an error, ignore and keep going
+ if err != nil {
+ continue
+ }
+ if d.name == search.name && d.tag == search.tag {
+ results = append(results, image)
+ break
+ }
+ }
+ }
+ if len(results) == 0 {
+ return &storage.Image{}, errors.Errorf("unable to find a name and tag match for %s in repotags", search)
+ } else if len(results) > 1 {
+ return &storage.Image{}, errors.Errorf("found multiple name and tag matches for %s in repotags", search)
+ }
+ return results[0], nil
+}