fix windows flags

This commit is contained in:
Pat Hickey
2021-01-12 09:51:09 -08:00
parent 75a9dc7fe2
commit 32f162aa78
3 changed files with 16 additions and 16 deletions

View File

@@ -86,7 +86,7 @@ fn file_access_mode_from_fdflags(fdflags: Fdflags, read: bool, write: bool) -> A
// For append, grant the handle FILE_APPEND_DATA access but *not* FILE_WRITE_DATA. // For append, grant the handle FILE_APPEND_DATA access but *not* FILE_WRITE_DATA.
// This makes the handle "append only". // This makes the handle "append only".
// Changes to the file pointer will be ignored (like POSIX's O_APPEND behavior). // Changes to the file pointer will be ignored (like POSIX's O_APPEND behavior).
if fdflags.contains(&Fdflags::APPEND) { if fdflags.contains(Fdflags::APPEND) {
access_mode.insert(AccessMode::FILE_APPEND_DATA); access_mode.insert(AccessMode::FILE_APPEND_DATA);
access_mode.remove(AccessMode::FILE_WRITE_DATA); access_mode.remove(AccessMode::FILE_WRITE_DATA);
} }

View File

@@ -147,13 +147,13 @@ impl TryFrom<&File> for Filestat {
impl From<Oflags> for CreationDisposition { impl From<Oflags> for CreationDisposition {
fn from(oflags: Oflags) -> Self { fn from(oflags: Oflags) -> Self {
if oflags.contains(&Oflags::CREAT) { if oflags.contains(Oflags::CREAT) {
if oflags.contains(&Oflags::EXCL) { if oflags.contains(Oflags::EXCL) {
CreationDisposition::CREATE_NEW CreationDisposition::CREATE_NEW
} else { } else {
CreationDisposition::CREATE_ALWAYS CreationDisposition::CREATE_ALWAYS
} }
} else if oflags.contains(&Oflags::TRUNC) { } else if oflags.contains(Oflags::TRUNC) {
CreationDisposition::TRUNCATE_EXISTING CreationDisposition::TRUNCATE_EXISTING
} else { } else {
CreationDisposition::OPEN_EXISTING CreationDisposition::OPEN_EXISTING
@@ -171,9 +171,9 @@ impl From<Fdflags> for Flags {
// treat I/O operations on files as synchronous. WASI might have an async-io API in the future. // treat I/O operations on files as synchronous. WASI might have an async-io API in the future.
// Technically, Windows only supports __WASI_FDFLAGS_SYNC, but treat all the flags as the same. // Technically, Windows only supports __WASI_FDFLAGS_SYNC, but treat all the flags as the same.
if fdflags.contains(&Fdflags::DSYNC) if fdflags.contains(Fdflags::DSYNC)
|| fdflags.contains(&Fdflags::RSYNC) || fdflags.contains(Fdflags::RSYNC)
|| fdflags.contains(&Fdflags::SYNC) || fdflags.contains(Fdflags::SYNC)
{ {
flags.insert(Flags::FILE_FLAG_WRITE_THROUGH); flags.insert(Flags::FILE_FLAG_WRITE_THROUGH);
} }

View File

@@ -72,7 +72,7 @@ fn file_access_mode_from_fdflags(fdflags: Fdflags, read: bool, write: bool) -> A
// For append, grant the handle FILE_APPEND_DATA access but *not* FILE_WRITE_DATA. // For append, grant the handle FILE_APPEND_DATA access but *not* FILE_WRITE_DATA.
// This makes the handle "append only". // This makes the handle "append only".
// Changes to the file pointer will be ignored (like POSIX's O_APPEND behavior). // Changes to the file pointer will be ignored (like POSIX's O_APPEND behavior).
if fdflags.contains(&Fdflags::APPEND) { if fdflags.contains(Fdflags::APPEND) {
access_mode.insert(AccessMode::FILE_APPEND_DATA); access_mode.insert(AccessMode::FILE_APPEND_DATA);
access_mode.remove(AccessMode::FILE_WRITE_DATA); access_mode.remove(AccessMode::FILE_WRITE_DATA);
} }
@@ -100,16 +100,16 @@ pub(crate) fn open_rights(
let mut needed_inheriting = input_rights.base | input_rights.inheriting; let mut needed_inheriting = input_rights.base | input_rights.inheriting;
// convert open flags // convert open flags
if oflags.contains(&Oflags::CREAT) { if oflags.contains(Oflags::CREAT) {
needed_base |= Rights::PATH_CREATE_FILE; needed_base |= Rights::PATH_CREATE_FILE;
} else if oflags.contains(&Oflags::TRUNC) { } else if oflags.contains(Oflags::TRUNC) {
needed_base |= Rights::PATH_FILESTAT_SET_SIZE; needed_base |= Rights::PATH_FILESTAT_SET_SIZE;
} }
// convert file descriptor flags // convert file descriptor flags
if fdflags.contains(&Fdflags::DSYNC) if fdflags.contains(Fdflags::DSYNC)
|| fdflags.contains(&Fdflags::RSYNC) || fdflags.contains(Fdflags::RSYNC)
|| fdflags.contains(&Fdflags::SYNC) || fdflags.contains(Fdflags::SYNC)
{ {
needed_inheriting |= Rights::FD_DATASYNC; needed_inheriting |= Rights::FD_DATASYNC;
needed_inheriting |= Rights::FD_SYNC; needed_inheriting |= Rights::FD_SYNC;
@@ -211,13 +211,13 @@ pub(crate) fn open(
) -> Result<Box<dyn Handle>> { ) -> Result<Box<dyn Handle>> {
use winx::file::{AccessMode, CreationDisposition, Flags}; use winx::file::{AccessMode, CreationDisposition, Flags};
let is_trunc = oflags.contains(&Oflags::TRUNC); let is_trunc = oflags.contains(Oflags::TRUNC);
if is_trunc { if is_trunc {
// Windows does not support append mode when opening for truncation // Windows does not support append mode when opening for truncation
// This is because truncation requires `GENERIC_WRITE` access, which will override the removal // This is because truncation requires `GENERIC_WRITE` access, which will override the removal
// of the `FILE_WRITE_DATA` permission. // of the `FILE_WRITE_DATA` permission.
if fdflags.contains(&Fdflags::APPEND) { if fdflags.contains(Fdflags::APPEND) {
return Err(Error::Notsup); return Err(Error::Notsup);
} }
} }
@@ -246,7 +246,7 @@ pub(crate) fn open(
return Err(Error::Loop); return Err(Error::Loop);
} }
// check if we are trying to open a file as a dir // check if we are trying to open a file as a dir
if file_type.is_file() && oflags.contains(&Oflags::DIRECTORY) { if file_type.is_file() && oflags.contains(Oflags::DIRECTORY) {
return Err(Error::Notdir); return Err(Error::Notdir);
} }
} }