Skip to content

Commit

Permalink
continue
Browse files Browse the repository at this point in the history
  • Loading branch information
Hywan committed Aug 31, 2021
1 parent c1328af commit cf52a2e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 12 deletions.
3 changes: 3 additions & 0 deletions lib/wasi/src/state/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,9 +554,12 @@ impl PreopenDirBuilder {
}
let path = self.path.clone().unwrap();

/*
if !path.exists() {
return Err(WasiStateCreationError::PreopenedDirectoryNotFound(path));
}
*/

if let Some(alias) = &self.alias {
validate_mapped_dir_alias(alias)?;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/wasi/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ impl WasiFs {
&path.to_string_lossy(),
&alias
);
let cur_dir_metadata = path.metadata().map_err(|e| {
let cur_dir_metadata = wasi_fs.fs_backing.metadata(path).map_err(|e| {
format!(
"Could not get metadata for file {:?}: {}",
path,
Expand Down
44 changes: 33 additions & 11 deletions tests/lib/wast/src/wasi_wast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::fs::File;
use std::io::{self, Read, Seek, Write};
use std::path::PathBuf;
use wasmer::{ImportObject, Instance, Module, Store};
use wasmer_vfs::{host_fs, mem_fs, FileSystem};
use wasmer_wasi::types::{__wasi_filesize_t, __wasi_timestamp_t};
use wasmer_wasi::{
generate_import_object_from_env, get_wasi_version, FsError, Pipe, VirtualFile, WasiEnv,
Expand Down Expand Up @@ -165,17 +166,37 @@ impl<'a> WasiTest<'a> {
new_dir.push(dir);
builder.map_dir(dir, new_dir)?;
}
let mut temp_dirs = vec![];
for alias in &self.temp_dirs {
let td = tempfile::tempdir()?;
builder.map_dir(alias, td.path())?;
temp_dirs.push(td);
}

builder.set_fs(match filesystem_kind {
WasiFileSystemKind::Host => Box::new(wasmer_vfs::host_fs::FileSystem::default()),
WasiFileSystemKind::InMemory => Box::new(wasmer_vfs::mem_fs::FileSystem::default()),
});
let mut host_temp_dirs_to_not_drop = vec![];

match filesystem_kind {
WasiFileSystemKind::Host => {
let fs = host_fs::FileSystem::default();

for alias in &self.temp_dirs {
let temp_dir = tempfile::tempdir()?;
builder.map_dir(alias, temp_dir.path())?;
host_temp_dirs_to_not_drop.push(temp_dir);
}

builder.set_fs(Box::new(fs));
}

WasiFileSystemKind::InMemory => {
let fs = mem_fs::FileSystem::default();
let mut temp_dir_index: usize = 0;

for alias in &self.temp_dirs {
let temp_dir_name =
PathBuf::from(format!("/.tmp_wasmer_wast_{}", temp_dir_index));
fs.create_dir(temp_dir_name.as_path())?;
builder.map_dir(alias, temp_dir_name)?;
temp_dir_index += 1;
}

builder.set_fs(Box::new(fs));
}
}

let out = builder
.args(&self.args)
Expand All @@ -184,7 +205,8 @@ impl<'a> WasiTest<'a> {
.stdout(Box::new(OutputCapturerer::new()))
.stderr(Box::new(OutputCapturerer::new()))
.finalize()?;
Ok((out, temp_dirs))

Ok((out, host_temp_dirs_to_not_drop))
}

/// Get the correct [`WasiVersion`] from the Wasm [`Module`].
Expand Down

0 comments on commit cf52a2e

Please sign in to comment.