Docker-DCO-1.1-Signed-off-by: Victor Vieux <victor.vieux@docker.com> (github: vieux)
| ... | ... |
@@ -169,9 +169,7 @@ func getContainersExport(srv *Server, version float64, w http.ResponseWriter, r |
| 169 | 169 |
return fmt.Errorf("Missing parameter")
|
| 170 | 170 |
} |
| 171 | 171 |
job := srv.Eng.Job("export", vars["name"])
|
| 172 |
- if err := job.Stdout.Add(w); err != nil {
|
|
| 173 |
- return err |
|
| 174 |
- } |
|
| 172 |
+ job.Stdout.Add(w) |
|
| 175 | 173 |
if err := job.Run(); err != nil {
|
| 176 | 174 |
return err |
| 177 | 175 |
} |
| ... | ... |
@@ -573,9 +571,7 @@ func getImagesGet(srv *Server, version float64, w http.ResponseWriter, r *http.R |
| 573 | 573 |
w.Header().Set("Content-Type", "application/x-tar")
|
| 574 | 574 |
} |
| 575 | 575 |
job := srv.Eng.Job("image_export", vars["name"])
|
| 576 |
- if err := job.Stdout.Add(w); err != nil {
|
|
| 577 |
- return err |
|
| 578 |
- } |
|
| 576 |
+ job.Stdout.Add(w) |
|
| 579 | 577 |
return job.Run() |
| 580 | 578 |
} |
| 581 | 579 |
|
| ... | ... |
@@ -806,7 +802,7 @@ func postContainersAttach(srv *Server, version float64, w http.ResponseWriter, r |
| 806 | 806 |
job.Setenv("stderr", r.Form.Get("stderr"))
|
| 807 | 807 |
job.Stdin.Add(inStream) |
| 808 | 808 |
job.Stdout.Add(outStream) |
| 809 |
- job.Stderr.Add(errStream) |
|
| 809 |
+ job.Stderr.Set(errStream) |
|
| 810 | 810 |
if err := job.Run(); err != nil {
|
| 811 | 811 |
fmt.Fprintf(outStream, "Error: %s\n", err) |
| 812 | 812 |
|
| ... | ... |
@@ -836,7 +832,7 @@ func wsContainersAttach(srv *Server, version float64, w http.ResponseWriter, r * |
| 836 | 836 |
job.Setenv("stderr", r.Form.Get("stderr"))
|
| 837 | 837 |
job.Stdin.Add(ws) |
| 838 | 838 |
job.Stdout.Add(ws) |
| 839 |
- job.Stderr.Add(ws) |
|
| 839 |
+ job.Stderr.Set(ws) |
|
| 840 | 840 |
if err := job.Run(); err != nil {
|
| 841 | 841 |
utils.Errorf("Error: %s", err)
|
| 842 | 842 |
} |
| ... | ... |
@@ -31,12 +31,20 @@ func (o *Output) Used() bool {
|
| 31 | 31 |
// Add attaches a new destination to the Output. Any data subsequently written |
| 32 | 32 |
// to the output will be written to the new destination in addition to all the others. |
| 33 | 33 |
// This method is thread-safe. |
| 34 |
-// FIXME: Add cannot fail |
|
| 35 |
-func (o *Output) Add(dst io.Writer) error {
|
|
| 34 |
+func (o *Output) Add(dst io.Writer) {
|
|
| 36 | 35 |
o.Mutex.Lock() |
| 37 | 36 |
defer o.Mutex.Unlock() |
| 38 | 37 |
o.dests = append(o.dests, dst) |
| 39 |
- return nil |
|
| 38 |
+} |
|
| 39 |
+ |
|
| 40 |
+// Set closes and remove existing destination and then attaches a new destination to |
|
| 41 |
+// the Output. Any data subsequently written to the output will be written to the new |
|
| 42 |
+// destination in addition to all the others. This method is thread-safe. |
|
| 43 |
+func (o *Output) Set(dst io.Writer) {
|
|
| 44 |
+ o.Close() |
|
| 45 |
+ o.Mutex.Lock() |
|
| 46 |
+ defer o.Mutex.Unlock() |
|
| 47 |
+ o.dests = []io.Writer{dst}
|
|
| 40 | 48 |
} |
| 41 | 49 |
|
| 42 | 50 |
// AddPipe creates an in-memory pipe with io.Pipe(), adds its writing end as a destination, |
| ... | ... |
@@ -95,9 +95,7 @@ func TestOutputAddEnv(t *testing.T) {
|
| 95 | 95 |
func TestOutputAddClose(t *testing.T) {
|
| 96 | 96 |
o := NewOutput() |
| 97 | 97 |
var s sentinelWriteCloser |
| 98 |
- if err := o.Add(&s); err != nil {
|
|
| 99 |
- t.Fatal(err) |
|
| 100 |
- } |
|
| 98 |
+ o.Add(&s) |
|
| 101 | 99 |
if err := o.Close(); err != nil {
|
| 102 | 100 |
t.Fatal(err) |
| 103 | 101 |
} |