Skip to content

Commit

Permalink
Merge #397
Browse files Browse the repository at this point in the history
397: Fix WASI FS abstraction for Windows r=MarkMcCaskey a=MarkMcCaskey



Co-authored-by: Mark McCaskey <[email protected]>
  • Loading branch information
bors[bot] and Mark McCaskey committed Apr 26, 2019
2 parents 263d592 + a6091e1 commit 6958f89
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 12 additions & 12 deletions lib/wasi/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::{
cell::Cell,
fs,
io::{self, Read, Seek, Write},
path::PathBuf,
time::SystemTime,
};
use wasmer_runtime_core::debug;
Expand Down Expand Up @@ -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<String, Inode>,
},
Expand Down Expand Up @@ -170,7 +173,7 @@ pub struct WasiFs {
}

impl WasiFs {
pub fn new(preopened_files: &[String]) -> Result<Self, String> {
pub fn new(preopened_dirs: &[String]) -> Result<Self, String> {
/*let repo = RepoOpener::new()
.create(true)
.open("mem://wasmer-test-fs", "")
Expand All @@ -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();
Expand Down
9 changes: 3 additions & 6 deletions lib/wasi/src/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 6958f89

Please sign in to comment.