Implement fd_fdstat_set_flags for Windows.
This commit implements `fd_fdstat_set_flags` for Windows. Additionally, it fixes a problem where `O_APPEND` was not working correctly because `GENERIC_WRITE` was always being set; as a result, `FILE_WRITE_DATA` could not be removed from the permission set to properly enable append-only mode. It also treats `O_TRUNC` with `O_APPEND` as an invalid argument error. This is because Windows cannot support these two flags together. To support `O_TRUNC`, the `GENERIC_WRITE` bit must be set for the file access flags. Setting this bit will cause `FILE_WRITE_DATA` to be set, which will not properly treat the file as append-only (it requires `FILE_APPEND_DATA` without `FILE_WRITE_DATA`).
This commit is contained in:
@@ -434,3 +434,20 @@ pub fn query_mode_information(handle: RawHandle) -> Result<FileModeInformation>
|
||||
|
||||
Ok(FileModeInformation::from_bits_truncate(info.Mode))
|
||||
}
|
||||
|
||||
pub fn reopen_file(handle: RawHandle, access_mode: AccessMode, flags: Flags) -> Result<RawHandle> {
|
||||
let new_handle = unsafe {
|
||||
winbase::ReOpenFile(
|
||||
handle,
|
||||
access_mode.bits(),
|
||||
winnt::FILE_SHARE_DELETE | winnt::FILE_SHARE_READ | winnt::FILE_SHARE_WRITE,
|
||||
flags.bits(),
|
||||
)
|
||||
};
|
||||
|
||||
if new_handle == winapi::um::handleapi::INVALID_HANDLE_VALUE {
|
||||
return Err(winerror::WinError::last());
|
||||
}
|
||||
|
||||
Ok(new_handle)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user