Skip to content

Commit

Permalink
preview 2 filesystem: allow stat on any opened fd
Browse files Browse the repository at this point in the history
since file perms is now more accurately the file's access mode, a file
open for writing was having problems here.

in reality i dont think it makes sense to restrict this based on the
perms. if a file is opened, you should be able to stat it.

this fixes the path_link test, which was broken by prior changes.
additionally, this fix lets the path_open_dirfd_not_dir test pass.
  • Loading branch information
Pat Hickey committed May 26, 2023
1 parent 3afc114 commit e7831fe
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ async fn path_open_read_write() {
run("path_open_read_write", true).await.unwrap()
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
#[should_panic]
async fn path_open_dirfd_not_dir() {
run("path_open_dirfd_not_dir", true).await.unwrap()
}
Expand Down
8 changes: 2 additions & 6 deletions crates/wasi/src/preview2/preview2/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,16 +352,12 @@ impl<T: WasiView> filesystem::Host for T {
let table = self.table();
if table.is_file(fd) {
let f = table.get_file(fd)?;
if !f.perms.contains(FilePerms::READ) {
return Err(ErrorCode::NotPermitted.into());
}
// No permissions check on stat: if opened, allowed to stat it
let meta = f.file.metadata()?;
Ok(descriptorstat_from(meta))
} else if table.is_dir(fd) {
let d = table.get_dir(fd)?;
if !d.perms.contains(DirPerms::READ) {
return Err(ErrorCode::NotPermitted.into());
}
// No permissions check on stat: if opened, allowed to stat it
let meta = d.dir.dir_metadata()?;
Ok(descriptorstat_from(meta))
} else {
Expand Down

0 comments on commit e7831fe

Please sign in to comment.