add preopened_dir to builder

This commit is contained in:
Pat Hickey
2020-12-11 16:38:44 -08:00
parent dfcdbfd0fe
commit 30d49d122c
2 changed files with 18 additions and 3 deletions

View File

@@ -26,8 +26,8 @@ getrandom = { version = "0.2.0", features = ["std"] }
wiggle = { path = "../wiggle", default-features = false, version = "0.21.0" }
tracing = "0.1.19"
system-interface = "0.2"
cap-std = "0.7"
cap-fs-ext = "0.7"
cap-std = "0.8"
cap-fs-ext = "0.8"
fs-set-times = "0.2.1"
cfg-if = "1"

View File

@@ -4,7 +4,7 @@ use crate::string_array::{StringArray, StringArrayError};
use crate::table::Table;
use crate::Error;
use std::cell::{RefCell, RefMut};
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::rc::Rc;
pub struct WasiCtx {
@@ -94,4 +94,19 @@ impl WasiCtxBuilder {
);
self
}
pub fn preopened_dir(
&mut self,
dir: Box<dyn WasiDir>,
path: impl AsRef<Path>,
) -> Result<&mut Self, Error> {
let base_caps = DirCaps::OPEN;
let inheriting_caps = DirCaps::OPEN;
self.0.table().push(DirEntry {
base_caps,
inheriting_caps,
preopen_path: Some(path.as_ref().to_owned()),
dir,
})?;
Ok(self)
}
}