]> Cypherpunks repositories - gostls13.git/commit
os: reject WriteAt if file opened in append mode
authorLE Manh Cuong <cuong.manhle.vn@gmail.com>
Mon, 11 Mar 2019 06:58:20 +0000 (13:58 +0700)
committerIan Lance Taylor <iant@golang.org>
Wed, 27 Mar 2019 17:04:57 +0000 (17:04 +0000)
commitc7f7f59368c3a964b8214018dc5100806b243938
treee41030f829315935e5206f9cdde544b9cfd59a77
parent5ee2290420889281637b536473a9a51ffd63dda4
os: reject WriteAt if file opened in append mode

WriteAt use pwrite syscall on *nix or WriteFile on Windows.

On Linux/Windows, these system calls always write to end of file in
append mode, regardless of offset parameter.

It is hard (maybe impossible) to make WriteAt work portably.

Making WriteAt returns an error if file is opened in append mode, we
guarantee to get consistent behavior between platforms, also prevent
user from accidently corrupting their data.

Fixes #30716

Change-Id: If83d935a22a29eed2ff8fe53d13d0b4798aa2b81
Reviewed-on: https://go-review.googlesource.com/c/go/+/166578
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
src/os/export_test.go
src/os/file.go
src/os/file_plan9.go
src/os/file_unix.go
src/os/file_windows.go
src/os/os_test.go