fix preopen dir to work on windows

This commit is contained in:
Pat Hickey
2021-01-21 16:08:49 -08:00
parent 16b42a5707
commit 12056885eb

View File

@@ -1,5 +1,4 @@
use anyhow::Context;
use std::fs::File;
use std::path::Path;
use wasi_c2::pipe::{ReadPipe, WritePipe};
use wasi_c2_cap_std_sync::WasiCtxBuilder;
@@ -25,9 +24,7 @@ pub fn instantiate(data: &[u8], bin_name: &str, workspace: Option<&Path>) -> any
if let Some(workspace) = workspace {
println!("preopen: {:?}", workspace);
let dirfd =
File::open(workspace).context(format!("error while preopening {:?}", workspace))?;
let preopen_dir = unsafe { cap_std::fs::Dir::from_std_file(dirfd) };
let preopen_dir = unsafe { cap_std::fs::Dir::open_ambient_dir(workspace) }?;
builder = builder.preopened_dir(preopen_dir, ".")?;
}