|
@@ -1218,6 +1218,9 @@ func cmdStream(cmd *exec.Cmd, input io.Reader) (io.ReadCloser, error) {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
+ // Ensure the command has exited before we clean anything up
|
|
|
+ done := make(chan struct{})
|
|
|
+
|
|
|
// Copy stdout to the returned pipe
|
|
|
go func() {
|
|
|
if err := cmd.Wait(); err != nil {
|
|
@@ -1225,9 +1228,16 @@ func cmdStream(cmd *exec.Cmd, input io.Reader) (io.ReadCloser, error) {
|
|
|
} else {
|
|
|
pipeW.Close()
|
|
|
}
|
|
|
+ close(done)
|
|
|
}()
|
|
|
|
|
|
- return pipeR, nil
|
|
|
+ return ioutils.NewReadCloserWrapper(pipeR, func() error {
|
|
|
+ // Close pipeR, and then wait for the command to complete before returning. We have to close pipeR first, as
|
|
|
+ // cmd.Wait waits for any non-file stdout/stderr/stdin to close.
|
|
|
+ err := pipeR.Close()
|
|
|
+ <-done
|
|
|
+ return err
|
|
|
+ }), nil
|
|
|
}
|
|
|
|
|
|
// NewTempArchive reads the content of src into a temporary file, and returns the contents
|