mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
use the same 'Used' method as before
Docker-DCO-1.1-Signed-off-by: Victor Vieux <victor.vieux@docker.com> (github: vieux)
This commit is contained in:
parent
0fb8a55753
commit
a33bc3018b
3 changed files with 13 additions and 1 deletions
3
api.go
3
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))
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue