Prechádzať zdrojové kódy

use the same 'Used' method as before

Docker-DCO-1.1-Signed-off-by: Victor Vieux <victor.vieux@docker.com> (github: vieux)
Victor Vieux 11 rokov pred
rodič
commit
a33bc3018b
3 zmenil súbory, kde vykonal 13 pridanie a 1 odobranie
  1. 3 0
      api.go
  2. 9 0
      engine/streams.go
  3. 1 1
      server.go

+ 3 - 0
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))
 	}

+ 9 - 0
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)

+ 1 - 1
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