From a33bc3018bf091725b7faca9a6039a07b6fd0ca7 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Fri, 10 Jan 2014 14:54:54 -0800 Subject: [PATCH] use the same 'Used' method as before Docker-DCO-1.1-Signed-off-by: Victor Vieux (github: vieux) --- api.go | 3 +++ engine/streams.go | 9 +++++++++ server.go | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/api.go b/api.go index 5e456bbd85..148202c2e3 100644 --- a/api.go +++ b/api.go @@ -521,6 +521,9 @@ func postImagesInsert(srv *Server, version float64, w http.ResponseWriter, r *ht job.SetenvBool("json", version > 1.0) job.Stdout.Add(w) if err := job.Run(); err != nil { + if !job.Stdout.Used() { + return err + } sf := utils.NewStreamFormatter(version > 1.0) w.Write(sf.FormatError(err)) } diff --git a/engine/streams.go b/engine/streams.go index 824f0a4ab2..fbce6e632a 100644 --- a/engine/streams.go +++ b/engine/streams.go @@ -12,6 +12,7 @@ type Output struct { sync.Mutex dests []io.Writer tasks sync.WaitGroup + used bool } // NewOutput returns a new Output object with no destinations attached. @@ -20,6 +21,13 @@ func NewOutput() *Output { return &Output{} } +// Return true if something was written on this output +func (o *Output) Used() bool { + o.Mutex.Lock() + defer o.Mutex.Unlock() + return o.used +} + // Add attaches a new destination to the Output. Any data subsequently written // to the output will be written to the new destination in addition to all the others. // This method is thread-safe. @@ -82,6 +90,7 @@ func (o *Output) AddString(dst *string) error { func (o *Output) Write(p []byte) (n int, err error) { o.Mutex.Lock() defer o.Mutex.Unlock() + o.used = true var firstErr error for _, dst := range o.dests { _, err := dst.Write(p) diff --git a/server.go b/server.go index ec3e101068..2057b477a1 100644 --- a/server.go +++ b/server.go @@ -563,7 +563,7 @@ func (srv *Server) ImageInsert(job *engine.Job) engine.Status { img, err = srv.runtime.Commit(c, "", "", img.Comment, img.Author, nil) if err != nil { out.Write(sf.FormatError(err)) - return engine.StatusOK + return engine.StatusErr } out.Write(sf.FormatStatus("", img.ID)) return engine.StatusOK