Skip to content

Commit 742c48e

Browse files
committed
windows: respect permission bits on file opening
Chmod toggles the FILE_ATTRIBUTES_READONLY flag depending on the permission bits. That's a bit odd but I guess some compromises were made at some point and this is what was chosen to map to a Unix concept that Windows doesn't really have in the same way. That's fine. However, the logic used in Chmod was forgotten from Open, which then manifested itself in various places, most recently, go modules' read-only behavior. This corresonds with the syscall CL 202439. Updates golang/go#35033 Change-Id: Id8e74c5205057a74a35eda213516780b79a2aed2 Reviewed-on: https://go-review.googlesource.com/c/sys/+/202440 Run-TryBot: Jason A. Donenfeld <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]> Reviewed-by: Alex Brainman <[email protected]>
1 parent 3e7259c commit 742c48e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

windows/syscall_windows.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,11 @@ func Open(path string, mode int, perm uint32) (fd Handle, err error) {
410410
default:
411411
createmode = OPEN_EXISTING
412412
}
413-
h, e := CreateFile(pathp, access, sharemode, sa, createmode, FILE_ATTRIBUTE_NORMAL, 0)
413+
var attrs uint32 = FILE_ATTRIBUTE_NORMAL
414+
if perm&S_IWRITE == 0 {
415+
attrs = FILE_ATTRIBUTE_READONLY
416+
}
417+
h, e := CreateFile(pathp, access, sharemode, sa, createmode, attrs, 0)
414418
return h, e
415419
}
416420

0 commit comments

Comments
 (0)