diff --git a/crates/wasi-c2/src/dir.rs b/crates/wasi-c2/src/dir.rs index 0e851cd293..1d4886d36f 100644 --- a/crates/wasi-c2/src/dir.rs +++ b/crates/wasi-c2/src/dir.rs @@ -26,6 +26,7 @@ pub trait WasiDir { fn unlink_file(&self, path: &str) -> Result<(), Error>; fn read_link(&self, path: &str) -> Result; fn get_filestat(&self) -> Result; + fn get_path_filestat(&self, path: &str) -> Result; fn rename(&self, path: &str, dest_dir: &dyn WasiDir, dest_path: &str) -> Result<(), Error>; fn hard_link( &self, @@ -349,7 +350,21 @@ impl WasiDir for cap_std::fs::Dir { Ok(link) } fn get_filestat(&self) -> Result { - let meta = self.metadata(".")?; + let meta = self.dir_metadata()?; + use cap_fs_ext::MetadataExt; + Ok(Filestat { + device_id: meta.dev(), + inode: meta.ino(), + filetype: FileType::from(&meta.file_type()), + nlink: meta.nlink(), + size: meta.len(), + atim: meta.accessed().map(|t| Some(t.into_std())).unwrap_or(None), + mtim: meta.modified().map(|t| Some(t.into_std())).unwrap_or(None), + ctim: meta.created().map(|t| Some(t.into_std())).unwrap_or(None), + }) + } + fn get_path_filestat(&self, path: &str) -> Result { + let meta = self.metadata(Path::new(path))?; use cap_fs_ext::MetadataExt; Ok(Filestat { device_id: meta.dev(), diff --git a/crates/wasi-c2/src/snapshots/preview_1.rs b/crates/wasi-c2/src/snapshots/preview_1.rs index 04deb9f80b..98e149fe8e 100644 --- a/crates/wasi-c2/src/snapshots/preview_1.rs +++ b/crates/wasi-c2/src/snapshots/preview_1.rs @@ -647,7 +647,8 @@ impl<'a> wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx { let table = self.table(); let dir_entry: Ref = table.get(u32::from(dirfd))?; let dir = dir_entry.get_cap(DirCaps::PATH_FILESTAT_GET)?; - todo!() + let filestat = dir.get_path_filestat(path.as_str()?.deref())?; + Ok(types::Filestat::from(filestat)) } fn path_filestat_set_times(