From 7cc967e709250af50473f9c8dcf3be4e9d518c03 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Mon, 20 May 2019 16:46:08 -0700 Subject: [PATCH] flip order of args in mapdir --- lib/wasi/src/lib.rs | 2 +- lib/wasi/src/state.rs | 14 +++++++------- src/bin/wasmer.rs | 13 ++++++++----- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/lib/wasi/src/lib.rs b/lib/wasi/src/lib.rs index 55459b74b..8621dc55e 100644 --- a/lib/wasi/src/lib.rs +++ b/lib/wasi/src/lib.rs @@ -30,7 +30,7 @@ pub fn generate_import_object( args: Vec>, envs: Vec>, preopened_files: Vec, - mapped_dirs: Vec<(PathBuf, String)>, + mapped_dirs: Vec<(String, PathBuf)>, ) -> ImportObject { let state_gen = move || { fn state_destructor(data: *mut c_void) { diff --git a/lib/wasi/src/state.rs b/lib/wasi/src/state.rs index 3b03162ba..979d63d4d 100644 --- a/lib/wasi/src/state.rs +++ b/lib/wasi/src/state.rs @@ -177,7 +177,7 @@ pub struct WasiFs { impl WasiFs { pub fn new( preopened_dirs: &[String], - mapped_dirs: &[(PathBuf, String)], + mapped_dirs: &[(String, PathBuf)], ) -> Result { debug!("wasi::fs::inodes"); let inodes = Arena::new(); @@ -218,28 +218,28 @@ impl WasiFs { .expect("Could not open fd"); } debug!("wasi::fs::mapped_dirs"); - for (src_dir, dest_dir) in mapped_dirs { - debug!("Attempting to open {:?} at {}", src_dir, dest_dir); + for (alias, real_dir) in mapped_dirs { + debug!("Attempting to open {:?} at {}", dest_dir, alias); // TODO: think about this let default_rights = 0x1FFFFFFF; // all rights - let cur_dir_metadata = src_dir + let cur_dir_metadata = real_dir .metadata() .expect("mapped dir not at previously verified location"); let kind = if cur_dir_metadata.is_dir() { Kind::Dir { parent: None, - path: src_dir.clone(), + path: real_dir.clone(), entries: Default::default(), } } else { return Err(format!( "WASI only supports pre-opened directories right now; found \"{:?}\"", - &src_dir, + &real_dir, )); }; // TODO: handle nested pats in `file` let inode_val = - InodeVal::from_file_metadata(&cur_dir_metadata, dest_dir.clone(), true, kind); + InodeVal::from_file_metadata(&cur_dir_metadata, alias.clone(), true, kind); let inode = wasi_fs.inodes.insert(inode_val); wasi_fs.inodes[inode].stat.st_ino = wasi_fs.inode_counter.get(); diff --git a/src/bin/wasmer.rs b/src/bin/wasmer.rs index 1c232e1e6..bc4da1c85 100644 --- a/src/bin/wasmer.rs +++ b/src/bin/wasmer.rs @@ -234,16 +234,19 @@ fn execute_wasm(options: &Run) -> Result<(), String> { let mapped_dirs = { let mut md = vec![]; for entry in options.mapped_dirs.iter() { - if let &[source, dest] = &entry.split(':').collect::>()[..] { - let pb = PathBuf::from(&source); + if let &[alias, real_dir] = &entry.split(':').collect::>()[..] { + let pb = PathBuf::from(&real_dir); if let Ok(pb_metadata) = pb.metadata() { if !pb_metadata.is_dir() { - return Err(format!("\"{}\" exists, but it is not a directory", &source)); + return Err(format!( + "\"{}\" exists, but it is not a directory", + &real_dir + )); } } else { - return Err(format!("Directory \"{}\" does not exist", &source)); + return Err(format!("Directory \"{}\" does not exist", &real_dir)); } - md.push((pb, dest.to_string())); + md.push((alias.to_string(), pb)); continue; } return Err(format!(