... | ... |
@@ -101,6 +101,26 @@ func (store *Store) List(pth string) ([]*Image, error) { |
101 | 101 |
return store.imageList(images), nil |
102 | 102 |
} |
103 | 103 |
|
104 |
+func (store *Store) Find(pth string) (*Image, error) { |
|
105 |
+ pth = path.Clean(pth) |
|
106 |
+ img, err := store.Get(pth) |
|
107 |
+ if err != nil { |
|
108 |
+ return nil, err |
|
109 |
+ } else if img != nil { |
|
110 |
+ return img, nil |
|
111 |
+ } |
|
112 |
+ |
|
113 |
+ 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) |
|
114 |
+ if err != nil { |
|
115 |
+ return nil, err |
|
116 |
+ } else if len(images) < 1 { |
|
117 |
+ return nil, nil |
|
118 |
+ } |
|
119 |
+ img = images[0].(*Image) |
|
120 |
+ img.store = store |
|
121 |
+ return img, nil |
|
122 |
+} |
|
123 |
+ |
|
104 | 124 |
func (store *Store) Get(id string) (*Image, error) { |
105 | 125 |
img, err := store.orm.Get(Image{}, id) |
106 | 126 |
if img == nil { |
... | ... |
@@ -835,7 +835,7 @@ func (srv *Server) CmdRun(stdin io.ReadCloser, stdout io.Writer, args ...string) |
835 | 835 |
cmdline = []string{"/bin/bash", "-i"} |
836 | 836 |
} |
837 | 837 |
// Find the image |
838 |
- img, err := srv.images.Get(name) |
|
838 |
+ img, err := srv.images.Find(name) |
|
839 | 839 |
if err != nil { |
840 | 840 |
return err |
841 | 841 |
} else if img == nil { |