From 26bc1785d3d69847d08527e97b273ede31c2a5ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Gaspard?= Date: Tue, 12 Jan 2021 00:48:28 +0100 Subject: [PATCH] wasi-common: add preopened_handle, to be able to open any handle --- crates/wasi-common/src/ctx.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/crates/wasi-common/src/ctx.rs b/crates/wasi-common/src/ctx.rs index e73fbb4ea630..103aee73a854 100644 --- a/crates/wasi-common/src/ctx.rs +++ b/crates/wasi-common/src/ctx.rs @@ -268,6 +268,22 @@ impl WasiCtxBuilder { self } + /// Add a preopened handle. + /// + /// This is the most generic function for adding a directory, but also the less easy to use. + pub fn preopened_handle, T: 'static + Handle>( + &mut self, + dir: T, + guest_path: P, + ) -> &mut Self { + let preopen = PendingPreopen::new(move || Ok(Box::new(dir))); + self.preopens + .as_mut() + .unwrap() + .push((guest_path.as_ref().to_owned(), preopen)); + self + } + /// Build a `WasiCtx`, consuming this `WasiCtxBuilder`. /// /// If any of the arguments or environment variables in this builder cannot be converted into