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

Fix error prompt for pull & import handler postImagesCreate.

Signed-off-by: He Simei <hesimei@zju.edu.cn>
This commit is contained in:
He Simei 2015-04-25 09:10:32 +08:00
parent 602fd4e14b
commit daad696e09

View file

@ -740,8 +740,9 @@ func (s *Server) postImagesCreate(eng *engine.Engine, version version.Version, w
} }
var ( var (
opErr error err error
useJSON = version.GreaterThan("1.0") useJSON = version.GreaterThan("1.0")
output = utils.NewWriteFlusher(w)
) )
if useJSON { if useJSON {
@ -763,11 +764,12 @@ func (s *Server) postImagesCreate(eng *engine.Engine, version version.Version, w
Parallel: version.GreaterThan("1.3"), Parallel: version.GreaterThan("1.3"),
MetaHeaders: metaHeaders, MetaHeaders: metaHeaders,
AuthConfig: authConfig, AuthConfig: authConfig,
OutStream: utils.NewWriteFlusher(w), OutStream: output,
Json: useJSON, Json: useJSON,
} }
opErr = s.daemon.Repositories().Pull(image, tag, imagePullConfig) err = s.daemon.Repositories().Pull(image, tag, imagePullConfig)
} else { //import } else { //import
if tag == "" { if tag == "" {
repo, tag = parsers.ParseRepositoryTag(repo) repo, tag = parsers.ParseRepositoryTag(repo)
@ -777,7 +779,7 @@ func (s *Server) postImagesCreate(eng *engine.Engine, version version.Version, w
imageImportConfig := &graph.ImageImportConfig{ imageImportConfig := &graph.ImageImportConfig{
Changes: r.Form["changes"], Changes: r.Form["changes"],
InConfig: r.Body, InConfig: r.Body,
OutStream: utils.NewWriteFlusher(w), OutStream: output,
Json: useJSON, Json: useJSON,
} }
@ -787,15 +789,19 @@ func (s *Server) postImagesCreate(eng *engine.Engine, version version.Version, w
} }
imageImportConfig.ContainerConfig = newConfig imageImportConfig.ContainerConfig = newConfig
opErr = s.daemon.Repositories().Import(src, repo, tag, imageImportConfig) err = s.daemon.Repositories().Import(src, repo, tag, imageImportConfig)
}
if opErr != nil { }
if err != nil {
if !output.Flushed() {
return err
}
sf := streamformatter.NewStreamFormatter(useJSON) sf := streamformatter.NewStreamFormatter(useJSON)
return fmt.Errorf(string(sf.FormatError(opErr))) output.Write(sf.FormatError(err))
} }
return nil return nil
} }
func (s *Server) getImagesSearch(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error { func (s *Server) getImagesSearch(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {