Skip to content

Commit

Permalink
os: fix handling of ErrShortWrite in (*File).Write
Browse files Browse the repository at this point in the history
Restore the handling of io.ErrShortWrite in (*File).Write:
if we write less than the requested amount, and there is no error from
the syscall, then return io.ErrShortWrite.

I can't figure out how to write a test for this. It would require a
non-pollable file (not a pipe) on a device that is almost but not
quite entirely full. The original code (https://golang.org/cl/36800043,
committed as part of https://golang.org/cl/36930044) does not have a test.

Fixes #20386.

Change-Id: Ied7b411e621e1eaf49f864f8db90069f276256f5
Reviewed-on: https://go-review.googlesource.com/43558
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
  • Loading branch information
ianlancetaylor committed May 17, 2017
1 parent 13cdd81 commit 0fd7de4
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/os/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,11 @@ func (f *File) Write(b []byte) (n int, err error) {

epipecheck(f, e)

return n, f.wrapErr("write", e)
if e != nil {
err = f.wrapErr("write", e)
}

return n, err
}

// WriteAt writes len(b) bytes to the File starting at byte offset off.
Expand Down

0 comments on commit 0fd7de4

Please sign in to comment.