Browse code

use the same 'Used' method as before

Docker-DCO-1.1-Signed-off-by: Victor Vieux <victor.vieux@docker.com> (github: vieux)

Victor Vieux authored on 2014/01/11 07:54:54
Showing 3 changed files
... ...
@@ -521,6 +521,9 @@ func postImagesInsert(srv *Server, version float64, w http.ResponseWriter, r *ht
521 521
 	job.SetenvBool("json", version > 1.0)
522 522
 	job.Stdout.Add(w)
523 523
 	if err := job.Run(); err != nil {
524
+		if !job.Stdout.Used() {
525
+			return err
526
+		}
524 527
 		sf := utils.NewStreamFormatter(version > 1.0)
525 528
 		w.Write(sf.FormatError(err))
526 529
 	}
... ...
@@ -12,6 +12,7 @@ type Output struct {
12 12
 	sync.Mutex
13 13
 	dests []io.Writer
14 14
 	tasks sync.WaitGroup
15
+	used  bool
15 16
 }
16 17
 
17 18
 // NewOutput returns a new Output object with no destinations attached.
... ...
@@ -20,6 +21,13 @@ func NewOutput() *Output {
20 20
 	return &Output{}
21 21
 }
22 22
 
23
+// Return true if something was written on this output
24
+func (o *Output) Used() bool {
25
+	o.Mutex.Lock()
26
+	defer o.Mutex.Unlock()
27
+	return o.used
28
+}
29
+
23 30
 // Add attaches a new destination to the Output. Any data subsequently written
24 31
 // to the output will be written to the new destination in addition to all the others.
25 32
 // This method is thread-safe.
... ...
@@ -82,6 +90,7 @@ func (o *Output) AddString(dst *string) error {
82 82
 func (o *Output) Write(p []byte) (n int, err error) {
83 83
 	o.Mutex.Lock()
84 84
 	defer o.Mutex.Unlock()
85
+	o.used = true
85 86
 	var firstErr error
86 87
 	for _, dst := range o.dests {
87 88
 		_, err := dst.Write(p)
... ...
@@ -563,7 +563,7 @@ func (srv *Server) ImageInsert(job *engine.Job) engine.Status {
563 563
 	img, err = srv.runtime.Commit(c, "", "", img.Comment, img.Author, nil)
564 564
 	if err != nil {
565 565
 		out.Write(sf.FormatError(err))
566
-		return engine.StatusOK
566
+		return engine.StatusErr
567 567
 	}
568 568
 	out.Write(sf.FormatStatus("", img.ID))
569 569
 	return engine.StatusOK