From 1d4b7d8fa1af95ce83f263a49ed24e686fa7cb62 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Thu, 26 Dec 2013 15:43:27 -0800 Subject: [PATCH] Make sure the cache lookup returns always the same result --- server.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/server.go b/server.go index 9f6842dbae..02486f9b5e 100644 --- a/server.go +++ b/server.go @@ -21,6 +21,7 @@ import ( "path" "path/filepath" "runtime" + "sort" "strconv" "strings" "sync" @@ -1694,16 +1695,13 @@ func (srv *Server) ImageGetCached(imgID string, config *Config) (*Image, error) } // Store the tree in a map of map (map[parentId][childId]) - imageMap := make(map[string]map[string]struct{}) + imageMap := make(map[string][]string) for _, img := range images { - if _, exists := imageMap[img.Parent]; !exists { - imageMap[img.Parent] = make(map[string]struct{}) - } - imageMap[img.Parent][img.ID] = struct{}{} + imageMap[img.Parent] = append(imageMap[img.Parent], img.ID) } - + sort.Strings(imageMap[imgID]) // Loop on the children of the given image and check the config - for elem := range imageMap[imgID] { + for _, elem := range imageMap[imgID] { img, err := srv.runtime.graph.Get(elem) if err != nil { return nil, err