Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix WASI FS abstraction for Windows #397

Merged
merged 2 commits into from
Apr 26, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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