diff --git a/api_test.go b/api_test.go index fc7eeed713..9d773301ef 100644 --- a/api_test.go +++ b/api_test.go @@ -68,7 +68,7 @@ func TestGetInfo(t *testing.T) { srv := &Server{runtime: runtime} - initialImages, err := srv.runtime.graph.All() + initialImages, err := srv.runtime.graph.Map() if err != nil { t.Fatal(err) } diff --git a/graph.go b/graph.go index c54725fdb4..09770f8e30 100644 --- a/graph.go +++ b/graph.go @@ -272,27 +272,16 @@ func (graph *Graph) Delete(name string) error { // Map returns a list of all images in the graph, addressable by ID. func (graph *Graph) Map() (map[string]*Image, error) { - // FIXME: this should replace All() - all, err := graph.All() + images := make(map[string]*Image) + err := graph.WalkAll(func(image *Image) { + images[image.ID] = image + }) if err != nil { return nil, err } - images := make(map[string]*Image, len(all)) - for _, image := range all { - images[image.ID] = image - } return images, nil } -// All returns a list of all images in the graph. -func (graph *Graph) All() ([]*Image, error) { - var images []*Image - err := graph.WalkAll(func(image *Image) { - images = append(images, image) - }) - return images, err -} - // WalkAll iterates over each image in the graph, and passes it to a handler. // The walking order is undetermined. func (graph *Graph) WalkAll(handler func(*Image)) error { diff --git a/graph_test.go b/graph_test.go index 32fb0ef441..471016938d 100644 --- a/graph_test.go +++ b/graph_test.go @@ -20,11 +20,11 @@ func TestInit(t *testing.T) { if _, err := os.Stat(graph.Root); err != nil { t.Fatal(err) } - // All() should be empty - if l, err := graph.All(); err != nil { + // Map() should be empty + if l, err := graph.Map(); err != nil { t.Fatal(err) } else if len(l) != 0 { - t.Fatalf("List() should return %d, not %d", 0, len(l)) + t.Fatalf("len(Map()) should return %d, not %d", 0, len(l)) } } @@ -76,11 +76,15 @@ func TestGraphCreate(t *testing.T) { if image.DockerVersion != VERSION { t.Fatalf("Wrong docker_version: should be '%s', not '%s'", VERSION, image.DockerVersion) } - if images, err := graph.All(); err != nil { + images, err := graph.Map() + if err != nil { t.Fatal(err) } else if l := len(images); l != 1 { t.Fatalf("Wrong number of images. Should be %d, not %d", 1, l) } + if images[image.ID] == nil { + t.Fatalf("Could not find image with id %s", image.ID) + } } func TestRegister(t *testing.T) { @@ -99,7 +103,7 @@ func TestRegister(t *testing.T) { if err != nil { t.Fatal(err) } - if images, err := graph.All(); err != nil { + if images, err := graph.Map(); err != nil { t.Fatal(err) } else if l := len(images); l != 1 { t.Fatalf("Wrong number of images. Should be %d, not %d", 1, l) @@ -274,7 +278,7 @@ func TestByParent(t *testing.T) { } func assertNImages(graph *Graph, t *testing.T, n int) { - if images, err := graph.All(); err != nil { + if images, err := graph.Map(); err != nil { t.Fatal(err) } else if actualN := len(images); actualN != n { t.Fatalf("Expected %d images, found %d", n, actualN) diff --git a/runtime_test.go b/runtime_test.go index a65d962fa6..3cd7a0a5d0 100644 --- a/runtime_test.go +++ b/runtime_test.go @@ -50,7 +50,7 @@ func cleanup(runtime *Runtime) error { container.Kill() runtime.Destroy(container) } - images, err := runtime.graph.All() + images, err := runtime.graph.Map() if err != nil { return err } @@ -123,13 +123,13 @@ func init() { // FIXME: test that ImagePull(json=true) send correct json output func GetTestImage(runtime *Runtime) *Image { - imgs, err := runtime.graph.All() + imgs, err := runtime.graph.Map() if err != nil { panic(err) } - for i := range imgs { - if imgs[i].ID == unitTestImageID { - return imgs[i] + for _, image := range imgs { + if image.ID == unitTestImageID { + return image } } panic(fmt.Errorf("Test image %v not found", unitTestImageID)) diff --git a/server.go b/server.go index 646cb44877..b27f149996 100644 --- a/server.go +++ b/server.go @@ -158,7 +158,7 @@ func (srv *Server) ImageInsert(name, url, path string, out io.Writer, sf *utils. } func (srv *Server) ImagesViz(out io.Writer) error { - images, _ := srv.runtime.graph.All() + images, _ := srv.runtime.graph.Map() if images == nil { return nil } @@ -247,7 +247,7 @@ func (srv *Server) Images(all bool, filter string) ([]APIImages, error) { } func (srv *Server) DockerInfo() *APIInfo { - images, _ := srv.runtime.graph.All() + images, _ := srv.runtime.graph.Map() var imgcount int if images == nil { imgcount = 0 @@ -1064,7 +1064,7 @@ func (srv *Server) ImageDelete(name string, autoPrune bool) ([]APIRmi, error) { func (srv *Server) ImageGetCached(imgID string, config *Config) (*Image, error) { // Retrieve all images - images, err := srv.runtime.graph.All() + images, err := srv.runtime.graph.Map() if err != nil { return nil, err }