1
0
mirror of https://github.com/golang/go synced 2024-11-13 17:20:22 -07:00

io/ioutil: make WriteFile notice errors from Close()

WriteFile should not successfully return if the file's
Close call failed.

Fixes #5644.

R=golang-dev, kr, r
CC=golang-dev
https://golang.org/cl/10067043
This commit is contained in:
Robert Obryk 2013-06-05 21:16:44 -07:00 committed by Rob Pike
parent 6bf6cae28e
commit 9614119007

View File

@ -78,10 +78,12 @@ func WriteFile(filename string, data []byte, perm os.FileMode) error {
return err return err
} }
n, err := f.Write(data) n, err := f.Write(data)
f.Close()
if err == nil && n < len(data) { if err == nil && n < len(data) {
err = io.ErrShortWrite err = io.ErrShortWrite
} }
if err1 := f.Close(); err == nil {
err = err1
}
return err return err
} }