mirror of
https://github.com/fluencelabs/wasmer
synced 2025-05-14 19:41:20 +00:00
Commented zbox until speed is fixed
This commit is contained in:
parent
1193d561e2
commit
ea58e0051b
@ -10,6 +10,7 @@ use std::{
|
|||||||
io::{self, Write},
|
io::{self, Write},
|
||||||
time::SystemTime,
|
time::SystemTime,
|
||||||
};
|
};
|
||||||
|
use wasmer_runtime_core::debug;
|
||||||
use zbox::{init_env as zbox_init_env, File, FileType, OpenOptions, Repo, RepoOpener};
|
use zbox::{init_env as zbox_init_env, File, FileType, OpenOptions, Repo, RepoOpener};
|
||||||
|
|
||||||
pub const MAX_SYMLINKS: usize = 100;
|
pub const MAX_SYMLINKS: usize = 100;
|
||||||
@ -49,7 +50,7 @@ pub struct Fd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct WasiFs {
|
pub struct WasiFs {
|
||||||
pub repo: Repo,
|
// pub repo: Repo,
|
||||||
pub name_map: HashMap<String, Inode>,
|
pub name_map: HashMap<String, Inode>,
|
||||||
pub inodes: Arena<InodeVal>,
|
pub inodes: Arena<InodeVal>,
|
||||||
pub fd_map: HashMap<u32, Fd>,
|
pub fd_map: HashMap<u32, Fd>,
|
||||||
@ -58,19 +59,27 @@ pub struct WasiFs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl WasiFs {
|
impl WasiFs {
|
||||||
|
|
||||||
pub fn new() -> Result<Self, String> {
|
pub fn new() -> Result<Self, String> {
|
||||||
|
debug!("wasi::fs::init");
|
||||||
zbox_init_env();
|
zbox_init_env();
|
||||||
Ok(Self {
|
debug!("wasi::fs::repo");
|
||||||
repo: RepoOpener::new()
|
// let repo = RepoOpener::new()
|
||||||
.create(true)
|
// .create(true)
|
||||||
.open("mem://wasmer-test-fs", "")
|
// .open("mem://wasmer-test-fs", "")
|
||||||
.map_err(|e| e.to_string())?,
|
// .map_err(|e| e.to_string())?;
|
||||||
|
debug!("wasi::fs::inodes");
|
||||||
|
let inodes = Arena::new();
|
||||||
|
let res = Ok(Self {
|
||||||
|
// repo: repo,
|
||||||
name_map: HashMap::new(),
|
name_map: HashMap::new(),
|
||||||
inodes: Arena::new(),
|
inodes: inodes,
|
||||||
fd_map: HashMap::new(),
|
fd_map: HashMap::new(),
|
||||||
next_fd: Cell::new(3),
|
next_fd: Cell::new(3),
|
||||||
inode_counter: Cell::new(1000),
|
inode_counter: Cell::new(1000),
|
||||||
})
|
});
|
||||||
|
debug!("wasi::fs::end");
|
||||||
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
@ -78,56 +87,57 @@ impl WasiFs {
|
|||||||
Some(match self.name_map.entry(path.to_string()) {
|
Some(match self.name_map.entry(path.to_string()) {
|
||||||
Entry::Occupied(o) => *o.get(),
|
Entry::Occupied(o) => *o.get(),
|
||||||
Entry::Vacant(v) => {
|
Entry::Vacant(v) => {
|
||||||
let file = if let Ok(file) = OpenOptions::new()
|
return None;
|
||||||
.read(true)
|
// let file = if let Ok(file) = OpenOptions::new()
|
||||||
.write(true)
|
// .read(true)
|
||||||
.create(false)
|
// .write(true)
|
||||||
.open(&mut self.repo, path)
|
// .create(false)
|
||||||
{
|
// .open(&mut self.repo, path)
|
||||||
file
|
// {
|
||||||
} else {
|
// file
|
||||||
return None;
|
// } else {
|
||||||
};
|
// return None;
|
||||||
|
// };
|
||||||
|
|
||||||
let metadata = file.metadata().unwrap();
|
// let metadata = file.metadata().unwrap();
|
||||||
let inode_index = {
|
// let inode_index = {
|
||||||
let index = self.inode_counter.get();
|
// let index = self.inode_counter.get();
|
||||||
self.inode_counter.replace(index + 1)
|
// self.inode_counter.replace(index + 1)
|
||||||
};
|
// };
|
||||||
|
|
||||||
let systime_to_nanos = |systime: SystemTime| {
|
// let systime_to_nanos = |systime: SystemTime| {
|
||||||
let duration = systime
|
// let duration = systime
|
||||||
.duration_since(SystemTime::UNIX_EPOCH)
|
// .duration_since(SystemTime::UNIX_EPOCH)
|
||||||
.expect("should always be after unix epoch");
|
// .expect("should always be after unix epoch");
|
||||||
duration.as_nanos() as u64
|
// duration.as_nanos() as u64
|
||||||
};
|
// };
|
||||||
|
|
||||||
let inode = self.inodes.insert(InodeVal {
|
// let inode = self.inodes.insert(InodeVal {
|
||||||
stat: __wasi_filestat_t {
|
// stat: __wasi_filestat_t {
|
||||||
st_dev: 0,
|
// st_dev: 0,
|
||||||
st_ino: inode_index,
|
// st_ino: inode_index,
|
||||||
st_filetype: match metadata.file_type() {
|
// st_filetype: match metadata.file_type() {
|
||||||
FileType::File => __WASI_FILETYPE_REGULAR_FILE,
|
// FileType::File => __WASI_FILETYPE_REGULAR_FILE,
|
||||||
FileType::Dir => __WASI_FILETYPE_DIRECTORY,
|
// FileType::Dir => __WASI_FILETYPE_DIRECTORY,
|
||||||
},
|
// },
|
||||||
st_nlink: 0,
|
// st_nlink: 0,
|
||||||
st_size: metadata.content_len() as u64,
|
// st_size: metadata.content_len() as u64,
|
||||||
st_atim: systime_to_nanos(SystemTime::now()),
|
// st_atim: systime_to_nanos(SystemTime::now()),
|
||||||
st_mtim: systime_to_nanos(metadata.modified_at()),
|
// st_mtim: systime_to_nanos(metadata.modified_at()),
|
||||||
st_ctim: systime_to_nanos(metadata.created_at()),
|
// st_ctim: systime_to_nanos(metadata.created_at()),
|
||||||
},
|
// },
|
||||||
is_preopened: false,
|
// is_preopened: false,
|
||||||
name: path.to_string(),
|
// name: path.to_string(),
|
||||||
kind: match metadata.file_type() {
|
// kind: match metadata.file_type() {
|
||||||
FileType::File => Kind::File { handle: file },
|
// FileType::File => Kind::File { handle: file },
|
||||||
FileType::Dir => Kind::Dir {
|
// FileType::Dir => Kind::Dir {
|
||||||
handle: file,
|
// handle: file,
|
||||||
entries: HashMap::new(),
|
// entries: HashMap::new(),
|
||||||
},
|
// },
|
||||||
},
|
// },
|
||||||
});
|
// });
|
||||||
v.insert(inode);
|
// v.insert(inode);
|
||||||
inode
|
// inode
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user