Преглед изворни кода

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

Guillaume J. Charmes пре 12 година
родитељ
комит
004a5310d9
3 измењених фајлова са 17 додато и 7 уклоњено
  1. 9 6
      commands.go
  2. 7 0
      graph.go
  3. 1 1
      tags.go

+ 9 - 6
commands.go

@@ -831,14 +831,17 @@ func (srv *Server) CmdRun(stdin io.ReadCloser, stdout io.Writer, args ...string)
 	container, err := srv.runtime.Create(config)
 	container, err := srv.runtime.Create(config)
 	if err != nil {
 	if err != nil {
 		// If container not found, try to pull it
 		// 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
 			return err
 		}
 		}
-		if container, err = srv.runtime.Create(config); err != nil {
-			return fmt.Errorf("Error creating container: %s", err)
-		}
 	}
 	}
 	if config.OpenStdin {
 	if config.OpenStdin {
 		cmd_stdin, err := container.StdinPipe()
 		cmd_stdin, err := container.StdinPipe()

+ 7 - 0
graph.go

@@ -6,6 +6,7 @@ import (
 	"os"
 	"os"
 	"path"
 	"path"
 	"path/filepath"
 	"path/filepath"
+	"strings"
 	"time"
 	"time"
 )
 )
 
 
@@ -27,6 +28,12 @@ func NewGraph(root string) (*Graph, error) {
 	}, nil
 	}, 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 {
 func (graph *Graph) Exists(id string) bool {
 	if _, err := graph.Get(id); err != nil {
 	if _, err := graph.Get(id); err != nil {
 		return false
 		return false

+ 1 - 1
tags.go

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