MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / preopened_dir

Method preopened_dir

crates/wasi/src/ctx.rs:300–326  ·  view source on GitHub ↗

Configures a "preopened directory" to be available to WebAssembly. By default WebAssembly does not have access to the filesystem because there are no preopened directories. All filesystem operations, such as opening a file, are done through a preexisting handle. This means that to provide WebAssembly access to a directory it must be configured through this API. WASI will also prevent access outs

(
        &mut self,
        host_path: impl AsRef<Path>,
        guest_path: impl AsRef<str>,
        dir_perms: DirPerms,
        file_perms: FilePerms,
    )

Source from the content-addressed store, hash-verified

298 /// # }
299 /// ```
300 pub fn preopened_dir(
301 &mut self,
302 host_path: impl AsRef<Path>,
303 guest_path: impl AsRef<str>,
304 dir_perms: DirPerms,
305 file_perms: FilePerms,
306 ) -> Result<&mut Self> {
307 let dir = cap_std::fs::Dir::open_ambient_dir(host_path.as_ref(), ambient_authority())?;
308 let mut open_mode = OpenMode::empty();
309 if dir_perms.contains(DirPerms::READ) {
310 open_mode |= OpenMode::READ;
311 }
312 if dir_perms.contains(DirPerms::MUTATE) {
313 open_mode |= OpenMode::WRITE;
314 }
315 self.filesystem.preopens.push((
316 Dir::new(
317 dir,
318 dir_perms,
319 file_perms,
320 open_mode,
321 self.filesystem.allow_blocking_current_thread,
322 ),
323 guest_path.as_ref().to_owned(),
324 ));
325 Ok(self)
326 }
327
328 /// Set the generator for the `wasi:random/random` number generator to the
329 /// custom generator specified.

Callers 11

wasi_contextFunction · 0.45
configure_wasip2Method · 0.45
set_legacy_p1_ctxMethod · 0.45
wasm_bench_createFunction · 0.45
newMethod · 0.45
p2_api_read_onlyFunction · 0.45
wasi_config_preopen_dirFunction · 0.45

Calls 6

OkFunction · 0.85
emptyFunction · 0.50
newFunction · 0.50
as_refMethod · 0.45
containsMethod · 0.45
pushMethod · 0.45

Tested by 6

newMethod · 0.36
p2_api_read_onlyFunction · 0.36