From 655188a7885584b1b0048c57b5458103a1ac9ea7 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Fri, 26 Apr 2019 13:17:36 -0700 Subject: [PATCH 1/2] Fix WASI FS abstraction for Windows --- lib/wasi/src/state.rs | 24 ++++++++++++------------ lib/wasi/src/syscalls/mod.rs | 9 +++------ 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/lib/wasi/src/state.rs b/lib/wasi/src/state.rs index eb7323bf705..b611bb2a7a5 100644 --- a/lib/wasi/src/state.rs +++ b/lib/wasi/src/state.rs @@ -9,6 +9,7 @@ use std::{ cell::Cell, fs, io::{self, Read, Seek, Write}, + path::PathBuf, time::SystemTime, }; use wasmer_runtime_core::debug; @@ -138,7 +139,9 @@ pub enum Kind { handle: WasiFile, }, Dir { - handle: WasiFile, + // TODO: wrap it like WasiFile + /// The path on the host system where the directory is located + path: PathBuf, /// The entries of a directory are lazily filled. entries: HashMap, }, @@ -170,7 +173,7 @@ pub struct WasiFs { } impl WasiFs { - pub fn new(preopened_files: &[String]) -> Result { + pub fn new(preopened_dirs: &[String]) -> Result { /*let repo = RepoOpener::new() .create(true) .open("mem://wasmer-test-fs", "") @@ -185,29 +188,26 @@ impl WasiFs { next_fd: Cell::new(3), inode_counter: Cell::new(1000), }; - for file in preopened_files { + for dir in preopened_dirs { debug!("Attempting to preopen {}", &file); // TODO: think about this let default_rights = 0x1FFFFFFF; // all rights - let cur_file: fs::File = fs::OpenOptions::new() - .read(true) - .open(file) - .expect("Could not find file"); - let cur_file_metadata = cur_file.metadata().unwrap(); - let kind = if cur_file_metadata.is_dir() { + let cur_dir = PathBuf::from(dir); + let cur_dir_metadata = cur_dir.metadata().expect("Could not find directory"); + let kind = if cur_dir_metadata.is_dir() { Kind::Dir { - handle: WasiFile::HostFile(cur_file), + path: cur_dir.clone(), entries: Default::default(), } } else { return Err(format!( "WASI only supports pre-opened directories right now; found \"{}\"", - file + &dir )); }; // TODO: handle nested pats in `file` let inode_val = - InodeVal::from_file_metadata(&cur_file_metadata, file.clone(), true, kind); + InodeVal::from_file_metadata(&cur_dir_metadata, dir.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/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index ad2835d776e..fcd1caaddfe 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -1242,15 +1242,12 @@ pub fn path_open( }; // TODO: handle __WASI_O_TRUNC on directories - let cur_dir = wasi_try!(open_options - .open(&cumulative_path) - .map_err(|_| __WASI_EINVAL)); - // TODO: refactor and reuse - let cur_file_metadata = cur_dir.metadata().unwrap(); + let cur_file_metadata = + wasi_try!(cumulative_path.metadata().map_err(|_| __WASI_EINVAL)); let kind = if cur_file_metadata.is_dir() { Kind::Dir { - handle: WasiFile::HostFile(cur_dir), + path: cumulative_path.clone(), entries: Default::default(), } } else { From a6091e1eea902229e202a1b15eb466ebe53927ec Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Fri, 26 Apr 2019 13:34:27 -0700 Subject: [PATCH 2/2] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a2fc7739c4..f46d5cbd89b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ All PRs to the Wasmer repository must add to this file. Blocks of changes will separated by version increments. ## **[Unreleased]** +- [#397](https://github.com/wasmerio/wasmer/pull/397) Fix WASI fs abstraction to work on Windows - [#390](https://github.com/wasmerio/wasmer/pull/390) Pin released wapm version and add it as a git submodule - [#383](https://github.com/wasmerio/wasmer/pull/383) Hook up wasi exit code to wasmer cli. - [#382](https://github.com/wasmerio/wasmer/pull/382) Improve error message on `--backend` flag to only suggest currently enabled backends