diff --git a/crates/wasi-c2/src/file.rs b/crates/wasi-c2/src/file.rs index c7530d3d9e..8c7a51e9de 100644 --- a/crates/wasi-c2/src/file.rs +++ b/crates/wasi-c2/src/file.rs @@ -87,14 +87,14 @@ impl std::ops::BitOr for OFlags { #[derive(Debug, Clone)] pub struct Filestat { - device_id: u64, - inode: u64, - filetype: Filetype, - nlink: u64, - size: u64, - atim: std::time::SystemTime, - mtim: std::time::SystemTime, - ctim: std::time::SystemTime, + pub device_id: u64, + pub inode: u64, + pub filetype: Filetype, + pub nlink: u64, + pub size: u64, + pub atim: std::time::SystemTime, + pub mtim: std::time::SystemTime, + pub ctim: std::time::SystemTime, } pub(crate) struct FileEntry { @@ -232,7 +232,7 @@ impl WasiFile for cap_std::fs::File { fn get_oflags(&self) -> Result { todo!("get_oflags is not implemented"); } - fn set_oflags(&self, flags: OFlags) -> Result<(), Error> { + fn set_oflags(&self, _flags: OFlags) -> Result<(), Error> { todo!("set_oflags is not implemented"); } fn get_filestat(&self) -> Result { @@ -244,9 +244,19 @@ impl WasiFile for cap_std::fs::File { filetype: self.get_filetype()?, nlink: meta.nlink(), size: meta.len(), - atim: meta.accessed()?.into_std(), - mtim: meta.modified()?.into_std(), - ctim: meta.created()?.into_std(), + // XXX handle these features not being available better: + atim: meta + .accessed() + .map(|t| t.into_std()) + .unwrap_or_else(|_| std::time::SystemTime::UNIX_EPOCH), + mtim: meta + .modified() + .map(|t| t.into_std()) + .unwrap_or_else(|_| std::time::SystemTime::UNIX_EPOCH), + ctim: meta + .created() + .map(|t| t.into_std()) + .unwrap_or_else(|_| std::time::SystemTime::UNIX_EPOCH), }) } fn set_filestat_size(&self, size: u64) -> Result<(), Error> { diff --git a/crates/wasi-c2/src/snapshots/preview_1.rs b/crates/wasi-c2/src/snapshots/preview_1.rs index 84e44488f5..f72e466335 100644 --- a/crates/wasi-c2/src/snapshots/preview_1.rs +++ b/crates/wasi-c2/src/snapshots/preview_1.rs @@ -1024,6 +1024,27 @@ impl From<&OFlags> for types::Oflags { } impl From for types::Filestat { fn from(stat: Filestat) -> types::Filestat { - todo!() + types::Filestat { + dev: stat.device_id, + ino: stat.inode, + filetype: types::Filetype::from(&stat.filetype), + nlink: stat.nlink, + size: stat.size, + atim: stat + .atim + .duration_since(std::time::UNIX_EPOCH) + .unwrap() + .as_nanos() as u64, + mtim: stat + .mtim + .duration_since(std::time::UNIX_EPOCH) + .unwrap() + .as_nanos() as u64, + ctim: stat + .ctim + .duration_since(std::time::UNIX_EPOCH) + .unwrap() + .as_nanos() as u64, + } } }