Remove flush(stdout) in pkg/chrootarchive/diff_unix.go and improve error reporting of flush() to fix #21103

pkg/chrootarchive/diff_unix.go erroneously calls flush on stdout, which tries to read from stdout returning an error.
This has been fixed by removing the call and by modifying flush to return errors and checking for these errors on calls to flush.

Signed-off-by: Amit Krishnan <krish.amit@gmail.com>
This commit is contained in:
Amit Krishnan 2016-03-14 13:22:05 -07:00
parent 6f2d8b411e
commit a9c6169138
3 changed files with 10 additions and 5 deletions

View File

@ -46,7 +46,10 @@ func untar() {
fatal(err)
}
// fully consume stdin in case it is zero padded
flush(os.Stdin)
if _, err := flush(os.Stdin); err != nil {
fatal(err)
}
os.Exit(0)
}

View File

@ -65,8 +65,10 @@ func applyLayer() {
fatal(fmt.Errorf("unable to encode layerSize JSON: %s", err))
}
flush(os.Stdout)
flush(os.Stdin)
if _, err := flush(os.Stdin); err != nil {
fatal(err)
}
os.Exit(0)
}

View File

@ -23,6 +23,6 @@ func fatal(err error) {
// flush consumes all the bytes from the reader discarding
// any errors
func flush(r io.Reader) {
io.Copy(ioutil.Discard, r)
func flush(r io.Reader) (bytes int64, err error) {
return io.Copy(ioutil.Discard, r)
}