From f5f26a510f15d96a320b668e10516bc068905b11 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Wed, 13 Mar 2013 13:23:59 -0700 Subject: [PATCH] 'docker inspect' supports pinned versions again (eg. 'docker inspect PATH:revision') --- commands/commands.go | 6 ++++-- fs/store.go | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/commands/commands.go b/commands/commands.go index f8c97cdff0..195ba21114 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -308,8 +308,10 @@ func (srv *Server) CmdInspect(stdin io.ReadCloser, stdout io.Writer, args ...str var obj interface{} if container := srv.containers.Get(name); container != nil { obj = container - //} else if image, err := srv.images.List(name); image != nil { - // obj = image + } else if image, err := srv.images.Find(name); err != nil { + return err + } else if image != nil { + obj = image } else { return errors.New("No such container or image: " + name) } diff --git a/fs/store.go b/fs/store.go index 7b8447105a..65ffd0db86 100644 --- a/fs/store.go +++ b/fs/store.go @@ -12,6 +12,7 @@ import ( "os" "path" "path/filepath" + "strings" "syscall" "time" ) @@ -128,7 +129,19 @@ func (store *Store) Find(pth string) (*Image, error) { return img, nil } - images, err := store.orm.Select(Image{}, "select images.* from images, paths where Path=? and paths.Image=images.Id order by images.Created desc limit 1", pth) + var q string + var args []interface{} + // FIXME: this breaks if the path contains a ':' + // If format is path:rev + if parts := strings.SplitN(pth, ":", 2); len(parts) == 2 { + q = "select Images.* from images, paths where Path=? and images.Id=? and paths.Image=images.Id" + args = []interface{}{parts[0], parts[1]} + // If format is path:rev + } else { + q = "select images.* from images, paths where Path=? and paths.Image=images.Id order by images.Created desc limit 1" + args = []interface{}{parts[0]} + } + images, err := store.orm.Select(Image{}, q, args...) if err != nil { return nil, err } else if len(images) < 1 {