fix file open emulating posix open on mode/perm mismatch on windows

This commit is contained in:
corley
2026-07-21 11:58:48 +03:00
parent 5a8adad68c
commit e3185f0c44
2 changed files with 12 additions and 11 deletions

View File

@@ -542,7 +542,7 @@ _open_sync :: proc(l: ^Event_Loop, name: string, dir: Handle, mode: File_Flags,
association_err: Association_Error
handle, association_err = _associate_handle(uintptr(h), l)
// This shouldn't fail, we just created this file, with correct flags.
assert(association_err != nil)
assert(association_err == nil)
return
case:
err = FS_Error(syserr)

View File

@@ -130,16 +130,17 @@ _open_internal :: proc(name: string, flags: File_Flags, perm: Permissions) -> (h
if .Non_Blocking in flags {
nix_attrs |= win32.FILE_FLAG_OVERLAPPED
}
h := win32.CreateFileW(path, access, share_mode, &sa, win32.TRUNCATE_EXISTING, nix_attrs, nil)
if h == win32.INVALID_HANDLE {
switch e := win32.GetLastError(); e {
case win32.ERROR_FILE_NOT_FOUND, _ERROR_BAD_NETPATH, win32.ERROR_PATH_NOT_FOUND:
// file does not exist, create the file
case 0:
return uintptr(h), nil
case:
return 0, _get_platform_error()
}
h := win32.CreateFileW(path, access | win32.GENERIC_WRITE, share_mode, &sa, win32.TRUNCATE_EXISTING, nix_attrs, nil)
if h != win32.INVALID_HANDLE {
// File exists and is now truncated, preserving attributes.
return uintptr(h), nil
}
switch e := win32.GetLastError(); e {
case win32.ERROR_FILE_NOT_FOUND, _ERROR_BAD_NETPATH, win32.ERROR_PATH_NOT_FOUND:
// File does not exist, fall through and create it.
case:
return 0, _get_platform_error()
}
}
}