var f *File
var err error
if r == nil {
- f, err = OpenFile(link, O_WRONLY|O_CREATE|O_EXCL, 0o666)
+ f, err = OpenFile(link, O_WRONLY|O_CREATE|O_EXCL, 0o444)
} else {
- f, err = r.OpenFile(link, O_WRONLY|O_CREATE|O_EXCL, 0o666)
+ f, err = r.OpenFile(link, O_WRONLY|O_CREATE|O_EXCL, 0o444)
}
if err == nil {
f.Close()
if flag&O_CLOEXEC == 0 {
sa = makeInheritSa()
}
- // We don't use CREATE_ALWAYS, because when opening a file with
- // FILE_ATTRIBUTE_READONLY these will replace an existing file
- // with a new, read-only one. See https://go.dev/issue/38225.
- //
- // Instead, we ftruncate the file after opening when O_TRUNC is set.
- var createmode uint32
var attrs uint32 = FILE_ATTRIBUTE_NORMAL
- switch {
- case flag&(O_CREAT|O_EXCL) == (O_CREAT | O_EXCL):
- createmode = CREATE_NEW
- attrs |= FILE_FLAG_OPEN_REPARSE_POINT // don't follow symlinks
- case flag&O_CREAT == O_CREAT:
- createmode = OPEN_ALWAYS
- default:
- createmode = OPEN_EXISTING
- }
if perm&S_IWRITE == 0 {
attrs = FILE_ATTRIBUTE_READONLY
}
const _FILE_FLAG_WRITE_THROUGH = 0x80000000
attrs |= _FILE_FLAG_WRITE_THROUGH
}
+ // We don't use CREATE_ALWAYS, because when opening a file with
+ // FILE_ATTRIBUTE_READONLY these will replace an existing file
+ // with a new, read-only one. See https://go.dev/issue/38225.
+ //
+ // Instead, we ftruncate the file after opening when O_TRUNC is set.
+ var createmode uint32
+ switch {
+ case flag&(O_CREAT|O_EXCL) == (O_CREAT | O_EXCL):
+ createmode = CREATE_NEW
+ attrs |= FILE_FLAG_OPEN_REPARSE_POINT // don't follow symlinks
+ case flag&O_CREAT == O_CREAT:
+ createmode = OPEN_ALWAYS
+ default:
+ createmode = OPEN_EXISTING
+ }
h, err := createFile(namep, access, sharemode, sa, createmode, attrs, 0)
if h == InvalidHandle {
if err == ERROR_ACCESS_DENIED && (attrs&FILE_FLAG_BACKUP_SEMANTICS == 0) {