From: Tobias Klauser Date: Wed, 17 May 2023 07:57:37 +0000 (+0200) Subject: os: set File.appendMode in NewFile if file was opened with O_APPEND X-Git-Tag: go1.21rc1~465 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=774f60223f9a2b1a4e2f3c042e5cea93fc90c6a8;p=gostls13.git os: set File.appendMode in NewFile if file was opened with O_APPEND To allow skipping the use of the copy_file_range syscall on Linux which isn't supported for destination files opened with O_APPEND, see comment in (*File).readFrom and https://man7.org/linux/man-pages/man2/copy_file_range.2.html#ERRORS Fixes #60181 Change-Id: Ie0b0050faab16858412928a3d1f96442619581eb Reviewed-on: https://go-review.googlesource.com/c/go/+/494915 TryBot-Result: Gopher Robot Reviewed-by: Bryan Mills Auto-Submit: Tobias Klauser Reviewed-by: Ian Lance Taylor Run-TryBot: Tobias Klauser --- diff --git a/src/os/file_unix.go b/src/os/file_unix.go index 3d3a8b2056..b8c27d8826 100644 --- a/src/os/file_unix.go +++ b/src/os/file_unix.go @@ -106,7 +106,11 @@ func NewFile(fd uintptr, name string) *File { if nb, err := unix.IsNonblock(int(fd)); err == nil && nb { kind = kindNonBlock } - return newFile(fd, name, kind) + f := newFile(fd, name, kind) + if flags, err := unix.Fcntl(int(fd), syscall.F_GETFL, 0); err == nil { + f.appendMode = flags&syscall.O_APPEND != 0 + } + return f } // newFileKind describes the kind of file to newFile.