Dir::open_file can just pass read/write as bools, centralizing FileCaps decoding
this way the impls of File/Dir don't need to know about any caps!
This commit is contained in:
@@ -5,7 +5,7 @@ use std::convert::TryInto;
|
|||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use wasi_common::{
|
use wasi_common::{
|
||||||
dir::{ReaddirCursor, ReaddirEntity, WasiDir},
|
dir::{ReaddirCursor, ReaddirEntity, WasiDir},
|
||||||
file::{FdFlags, FileCaps, FileType, Filestat, OFlags, WasiFile},
|
file::{FdFlags, FileType, Filestat, OFlags, WasiFile},
|
||||||
Error, ErrorExt,
|
Error, ErrorExt,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -26,7 +26,8 @@ impl WasiDir for Dir {
|
|||||||
symlink_follow: bool,
|
symlink_follow: bool,
|
||||||
path: &str,
|
path: &str,
|
||||||
oflags: OFlags,
|
oflags: OFlags,
|
||||||
caps: FileCaps,
|
read: bool,
|
||||||
|
write: bool,
|
||||||
fdflags: FdFlags,
|
fdflags: FdFlags,
|
||||||
) -> Result<Box<dyn WasiFile>, Error> {
|
) -> Result<Box<dyn WasiFile>, Error> {
|
||||||
use cap_fs_ext::{FollowSymlinks, OpenOptionsFollowExt};
|
use cap_fs_ext::{FollowSymlinks, OpenOptionsFollowExt};
|
||||||
@@ -43,11 +44,10 @@ impl WasiDir for Dir {
|
|||||||
if oflags.contains(OFlags::TRUNCATE) {
|
if oflags.contains(OFlags::TRUNCATE) {
|
||||||
opts.truncate(true);
|
opts.truncate(true);
|
||||||
}
|
}
|
||||||
if caps.contains(FileCaps::WRITE)
|
if read {
|
||||||
|| caps.contains(FileCaps::DATASYNC)
|
opts.read(true);
|
||||||
|| caps.contains(FileCaps::ALLOCATE)
|
}
|
||||||
|| caps.contains(FileCaps::FILESTAT_SET_SIZE)
|
if write {
|
||||||
{
|
|
||||||
opts.write(true);
|
opts.write(true);
|
||||||
} else {
|
} else {
|
||||||
// If not opened write, open read. This way the OS lets us open the file.
|
// If not opened write, open read. This way the OS lets us open the file.
|
||||||
@@ -55,9 +55,6 @@ impl WasiDir for Dir {
|
|||||||
// get_cap check.
|
// get_cap check.
|
||||||
opts.read(true);
|
opts.read(true);
|
||||||
}
|
}
|
||||||
if caps.contains(FileCaps::READ) {
|
|
||||||
opts.read(true);
|
|
||||||
}
|
|
||||||
if fdflags.contains(FdFlags::APPEND) {
|
if fdflags.contains(FdFlags::APPEND) {
|
||||||
opts.append(true);
|
opts.append(true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,8 @@ pub trait WasiDir {
|
|||||||
symlink_follow: bool,
|
symlink_follow: bool,
|
||||||
path: &str,
|
path: &str,
|
||||||
oflags: OFlags,
|
oflags: OFlags,
|
||||||
caps: FileCaps,
|
read: bool,
|
||||||
|
write: bool,
|
||||||
fdflags: FdFlags,
|
fdflags: FdFlags,
|
||||||
) -> Result<Box<dyn WasiFile>, Error>;
|
) -> Result<Box<dyn WasiFile>, Error>;
|
||||||
fn open_dir(&self, symlink_follow: bool, path: &str) -> Result<Box<dyn WasiDir>, Error>;
|
fn open_dir(&self, symlink_follow: bool, path: &str) -> Result<Box<dyn WasiDir>, Error>;
|
||||||
|
|||||||
@@ -813,7 +813,11 @@ impl<'a> wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
|
|||||||
|
|
||||||
let file_caps = dir_entry.child_file_caps(FileCaps::from(&fs_rights_base));
|
let file_caps = dir_entry.child_file_caps(FileCaps::from(&fs_rights_base));
|
||||||
let dir = dir_entry.get_cap(required_caps)?;
|
let dir = dir_entry.get_cap(required_caps)?;
|
||||||
let file = dir.open_file(symlink_follow, path.deref(), oflags, file_caps, fdflags)?;
|
let read = file_caps.contains(FileCaps::READ);
|
||||||
|
let write = file_caps.contains(FileCaps::WRITE)
|
||||||
|
|| file_caps.contains(FileCaps::ALLOCATE)
|
||||||
|
|| file_caps.contains(FileCaps::FILESTAT_SET_SIZE);
|
||||||
|
let file = dir.open_file(symlink_follow, path.deref(), oflags, read, write, fdflags)?;
|
||||||
drop(dir);
|
drop(dir);
|
||||||
let fd = table.push(Box::new(FileEntry::new(file_caps, file)))?;
|
let fd = table.push(Box::new(FileEntry::new(file_caps, file)))?;
|
||||||
Ok(types::Fd::from(fd))
|
Ok(types::Fd::from(fd))
|
||||||
|
|||||||
Reference in New Issue
Block a user