diff --git a/core/nbio/impl_windows.odin b/core/nbio/impl_windows.odin index adf2d5351..162092a80 100644 --- a/core/nbio/impl_windows.odin +++ b/core/nbio/impl_windows.odin @@ -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) diff --git a/core/os/file_windows.odin b/core/os/file_windows.odin index 3a9e90fed..ab1209c5b 100644 --- a/core/os/file_windows.odin +++ b/core/os/file_windows.odin @@ -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() } } }