1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Try to fetch missing base only on "not found" error

This commit is contained in:
Guillaume J. Charmes 2013-03-26 05:28:17 -07:00
parent 91d78a10c3
commit 004a5310d9
3 changed files with 17 additions and 7 deletions

View file

@ -831,14 +831,17 @@ func (srv *Server) CmdRun(stdin io.ReadCloser, stdout io.Writer, args ...string)
container, err := srv.runtime.Create(config)
if err != nil {
// If container not found, try to pull it
// FIXME: not found != error
fmt.Fprintf(stdout, "Image %s not found, trying to pull it from registry.\n", config.Image)
if err = srv.CmdPull(stdin, stdout, config.Image); err != nil {
if srv.runtime.graph.IsNotExist(err) {
fmt.Fprintf(stdout, "Image %s not found, trying to pull it from registry.\n", config.Image)
if err = srv.CmdPull(stdin, stdout, config.Image); err != nil {
return err
}
if container, err = srv.runtime.Create(config); err != nil {
return err
}
} else {
return err
}
if container, err = srv.runtime.Create(config); err != nil {
return fmt.Errorf("Error creating container: %s", err)
}
}
if config.OpenStdin {
cmd_stdin, err := container.StdinPipe()

View file

@ -6,6 +6,7 @@ import (
"os"
"path"
"path/filepath"
"strings"
"time"
)
@ -27,6 +28,12 @@ func NewGraph(root string) (*Graph, error) {
}, nil
}
// FIXME: Implement error subclass instead of looking at the error text
// Note: This is the way golang implements os.IsNotExists on Plan9
func (graph *Graph) IsNotExist(err error) bool {
return err != nil && strings.Contains(err.Error(), "does not exist")
}
func (graph *Graph) Exists(id string) bool {
if _, err := graph.Get(id); err != nil {
return false

View file

@ -75,7 +75,7 @@ func (store *TagStore) LookupImage(name string) (*Image, error) {
if i, err := store.GetImage(repoAndTag[0], repoAndTag[1]); err != nil {
return nil, err
} else if i == nil {
return nil, fmt.Errorf("No such image: %s", name)
return nil, fmt.Errorf("Image does not exist: %s", name)
} else {
img = i
}