aboutsummaryrefslogtreecommitdiff
path: root/src/syscall/syscall_windows.go
diff options
context:
space:
mode:
authorqmuntal <quimmuntal@gmail.com>2024-10-16 16:18:45 +0200
committerQuim Muntal <quimmuntal@gmail.com>2024-10-18 04:09:36 +0000
commit6853d89477e0886c7c96b08e7efaf74abedfcf71 (patch)
treef25d731e65c81359dc51c1f6fd7b5afdaec6b68a /src/syscall/syscall_windows.go
parente45c125a3c343767b3bb68f3512d8cffbf7691b9 (diff)
downloadgo-6853d89477e0886c7c96b08e7efaf74abedfcf71.tar.xz
syscall: keep write access when O_TRUNC is used on Windows
CL 618836 introduces a regression where O_APPEND and O_TRUNC could not be used together on Windows. This CL fixes the issue by keeping the write access when O_TRUNC is used , which is required when overwriting data (as per the file access rights docs: https://learn.microsoft.com/en-us/windows/win32/fileio/file-access-rights-constants). Fixes #69902. Change-Id: I77ec60ca6929124dd4490bdad6c3280c4db3efcb Reviewed-on: https://go-review.googlesource.com/c/go/+/620575 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Alex Brainman <alex.brainman@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com>
Diffstat (limited to 'src/syscall/syscall_windows.go')
-rw-r--r--src/syscall/syscall_windows.go6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/syscall/syscall_windows.go b/src/syscall/syscall_windows.go
index db1f4f2ba4..67a71dfc76 100644
--- a/src/syscall/syscall_windows.go
+++ b/src/syscall/syscall_windows.go
@@ -362,8 +362,12 @@ func Open(name string, flag int, perm uint32) (fd Handle, err error) {
access |= GENERIC_WRITE
}
if flag&O_APPEND != 0 {
- access &^= GENERIC_WRITE
access |= FILE_APPEND_DATA
+ // Remove GENERIC_WRITE access unless O_TRUNC is set,
+ // in which case we need it to truncate the file.
+ if flag&O_TRUNC == 0 {
+ access &^= GENERIC_WRITE
+ }
}
sharemode := uint32(FILE_SHARE_READ | FILE_SHARE_WRITE)
var sa *SecurityAttributes