summaryrefslogtreecommitdiff
path: root/libpod/image/image.go
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2018-03-21 13:08:32 -0500
committerAtomic Bot <atomic-devel@projectatomic.io>2018-03-22 19:06:51 +0000
commitd364d41e1b1cf42d11b383fb02fbaa07e8b156f7 (patch)
treeced7036c6dbb7e6a6659f79153618b910009386e /libpod/image/image.go
parent2cc51dbb1c0eff1d193e41a8d7e898830c186791 (diff)
downloadpodman-d364d41e1b1cf42d11b383fb02fbaa07e8b156f7.tar.gz
podman-d364d41e1b1cf42d11b383fb02fbaa07e8b156f7.tar.bz2
podman-d364d41e1b1cf42d11b383fb02fbaa07e8b156f7.zip
Removing tagged images change in behavior
An image name is really just a tag. When an image has multiple tags, we should be able to "delete" the one of its tags without harm. In this case, the "delete' is really a form of Untag (removing the tag from the image). If an image has multiple tags and the user tries to delete by ID without force, this should be denied because when you delete by ID there is no distinguishing it like image tags. Signed-off-by: baude <bbaude@redhat.com> Closes: #528 Approved by: mheon
Diffstat (limited to 'libpod/image/image.go')
-rw-r--r--libpod/image/image.go57
1 files changed, 57 insertions, 0 deletions
diff --git a/libpod/image/image.go b/libpod/image/image.go
index 633a682cc..b6e15e361 100644
--- a/libpod/image/image.go
+++ b/libpod/image/image.go
@@ -685,3 +685,60 @@ func Import(path, reference string, writer io.Writer, signingOptions SigningOpti
}
return runtime.NewFromLocal(reference)
}
+
+// MatchRepoTag takes a string and tries to match it against an
+// image's repotags
+func (i *Image) MatchRepoTag(input string) (string, error) {
+ results := make(map[int][]string)
+ var maxCount int
+ // first check if we have an exact match with the input
+ if util.StringInSlice(input, i.Names()) {
+ return input, nil
+ }
+ // next check if we are missing the tag
+ dcImage, err := decompose(input)
+ if err != nil {
+ return "", err
+ }
+ for _, repoName := range i.Names() {
+ count := 0
+ dcRepoName, err := decompose(repoName)
+ if err != nil {
+ return "", err
+ }
+ if dcRepoName.registry == dcImage.registry && dcImage.registry != "" {
+ count++
+ }
+ if dcRepoName.name == dcImage.name && dcImage.name != "" {
+ count++
+ } else if splitString(dcRepoName.name) == splitString(dcImage.name) {
+ count++
+ }
+ if dcRepoName.tag == dcImage.tag {
+ count++
+ }
+ results[count] = append(results[count], repoName)
+ if count > maxCount {
+ maxCount = count
+ }
+ }
+ if maxCount == 0 {
+ return "", errors.Errorf("unable to match user input to any specific repotag")
+ }
+ if len(results[maxCount]) > 1 {
+ return "", errors.Errorf("user input matched multiple repotags for the image")
+ }
+ return results[maxCount][0], nil
+}
+
+// splitString splits input string by / and returns the last array item
+func splitString(input string) string {
+ split := strings.Split(input, "/")
+ return split[len(split)-1]
+}
+
+// InputIsID returns a bool if the user input for an image
+// is the image's partial or full id
+func (i *Image) InputIsID() bool {
+ return strings.HasPrefix(i.ID(), i.InputName)
+}