diff --git a/crates/wasi-c2/src/error.rs b/crates/wasi-c2/src/error.rs index f4a940283d..bb63ae6db0 100644 --- a/crates/wasi-c2/src/error.rs +++ b/crates/wasi-c2/src/error.rs @@ -34,6 +34,9 @@ pub enum Error { #[error("Unexpected IoError: {0}")] UnexpectedIo(#[source] std::io::Error), + #[error("Unsupported operation: {0}")] + Unsupported(String), + // Below this, all variants are from the `$errno` type: /// Errno::TooBig: Argument list too long #[error("TooBig: Argument list too long")] diff --git a/crates/wasi-c2/src/file.rs b/crates/wasi-c2/src/file.rs index cbe5e2ccd5..d875be4f99 100644 --- a/crates/wasi-c2/src/file.rs +++ b/crates/wasi-c2/src/file.rs @@ -24,6 +24,7 @@ pub enum Filetype { SocketStream, } +#[derive(Debug, Copy, Clone, PartialEq, Eq)] pub struct FdFlags { flags: u32, } @@ -42,6 +43,7 @@ impl FdFlags { // etc } +#[derive(Debug, Copy, Clone, PartialEq, Eq)] pub struct OFlags { flags: u32, } @@ -187,10 +189,19 @@ impl WasiFile for cap_std::fs::File { Ok(OFlags::RDWR) } } - fn set_oflags(&self, _flags: OFlags) -> Result<(), Error> { - // XXX cap-std::fs::Permissions does not export a constructor to build this out of - #[allow(unreachable_code)] - self.set_permissions(todo!())?; + fn set_oflags(&self, flags: OFlags) -> Result<(), Error> { + #![allow(unreachable_code, unused_variables)] + cfg_if! { + if #[cfg(unix)] { + use std::os::unix::fs::PermissionsExt; + use cap_std::fs::Permissions; + use std::fs::Permissions as StdPermissions; + let flags = todo!("normalize to unix flags {:?}", flags); + self.set_permissions(Permissions::from_std(StdPermissions::from_mode(flags)))?; + } else { + Err(Error::Unsupported("set oflags on non-unix host system".to_owned())) + } + } Ok(()) } fn get_filestat(&self) -> Result { diff --git a/crates/wasi-c2/src/snapshots/preview_1.rs b/crates/wasi-c2/src/snapshots/preview_1.rs index d726a3dccb..731b3377b7 100644 --- a/crates/wasi-c2/src/snapshots/preview_1.rs +++ b/crates/wasi-c2/src/snapshots/preview_1.rs @@ -75,6 +75,7 @@ impl From for types::Errno { Error::DirNotCapable { .. } => Errno::Notcapable, Error::NotCapable => Errno::Notcapable, Error::TableOverflow => Errno::Overflow, + Error::Unsupported { .. } => Errno::Notcapable, // XXX is this reasonable? } } }