From 44b3e8d51b655d68d0a253c48c027360ff8c3a97 Mon Sep 17 00:00:00 2001 From: Nick Stenning Date: Fri, 28 Jun 2013 17:06:00 +0100 Subject: [PATCH] Reverse priority of tag lookup in TagStore.GetImage Currently, if you have the following images: foo/bar 1 23b27d50fb49 foo/bar 2 f2b86ec3fcc4 And you issue the following command: docker tag foo/bar:2 foo/bar latest docker will tag the "wrong" image, because the image id for foo/bar:1 starts with a "2". That is, you'll end up with the following: foo/bar 1 23b27d50fb49 foo/bar 2 f2b86ec3fcc4 foo/bar latest 23b27d50fb49 This commit reverses the priority given to tags vs. image ids in the construction `/:`, meaning that if a tag that is an exact match for the specified `tagOrId`, it will be tagged in preference to an image with an id that happens to start with the correct character sequence. --- tags.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tags.go b/tags.go index 9ad9d10d05..21c13bdfb2 100644 --- a/tags.go +++ b/tags.go @@ -204,15 +204,15 @@ func (store *TagStore) GetImage(repoName, tagOrID string) (*Image, error) { } else if repo == nil { return nil, nil } - //go through all the tags, to see if tag is in fact an ID + if revision, exists := repo[tagOrID]; exists { + return store.graph.Get(revision) + } + // If no matching tag is found, search through images for a matching image id for _, revision := range repo { if strings.HasPrefix(revision, tagOrID) { return store.graph.Get(revision) } } - if revision, exists := repo[tagOrID]; exists { - return store.graph.Get(revision) - } return nil, nil }