From: Ian Lance Taylor Date: Wed, 17 May 2017 00:41:42 +0000 (-0700) Subject: os: fix handling of ErrShortWrite in (*File).Write X-Git-Tag: go1.9beta1~242 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=0fd7de4971c89e782434a402dbb69c5fd17457f9;p=gostls13.git os: fix handling of ErrShortWrite in (*File).Write 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 Reviewed-by: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- diff --git a/src/os/file.go b/src/os/file.go index b5a1bb8c0d..c5db78fe2e 100644 --- a/src/os/file.go +++ b/src/os/file.go @@ -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.