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 <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
This commit is contained in:
Tobias Klauser 2023-05-17 09:57:37 +02:00 committed by Gopher Robot
parent 27906bb74a
commit 774f60223f
1 changed files with 5 additions and 1 deletions

View File

@ -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.