mirror of
https://github.com/fluencelabs/wasmer
synced 2024-12-13 22:25:40 +00:00
fix file metadata wasi test
This commit is contained in:
parent
edae361689
commit
8a177363f4
@ -464,3 +464,64 @@ pub fn host_file_type_to_wasi_file_type(file_type: fs::FileType) -> __wasi_filet
|
|||||||
__WASI_FILETYPE_UNKNOWN
|
__WASI_FILETYPE_UNKNOWN
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_stat_for_kind(kind: &Kind) -> Option<__wasi_filestat_t> {
|
||||||
|
match kind {
|
||||||
|
Kind::File { handle } => match handle {
|
||||||
|
WasiFile::HostFile(hf) => {
|
||||||
|
let md = hf.metadata().ok()?;
|
||||||
|
|
||||||
|
Some(__wasi_filestat_t {
|
||||||
|
st_filetype: host_file_type_to_wasi_file_type(md.file_type()),
|
||||||
|
st_size: md.len(),
|
||||||
|
st_atim: md
|
||||||
|
.accessed()
|
||||||
|
.ok()?
|
||||||
|
.duration_since(SystemTime::UNIX_EPOCH)
|
||||||
|
.ok()?
|
||||||
|
.as_nanos() as u64,
|
||||||
|
st_mtim: md
|
||||||
|
.modified()
|
||||||
|
.ok()?
|
||||||
|
.duration_since(SystemTime::UNIX_EPOCH)
|
||||||
|
.ok()?
|
||||||
|
.as_nanos() as u64,
|
||||||
|
st_ctim: md
|
||||||
|
.created()
|
||||||
|
.ok()?
|
||||||
|
.duration_since(SystemTime::UNIX_EPOCH)
|
||||||
|
.ok()?
|
||||||
|
.as_nanos() as u64,
|
||||||
|
..__wasi_filestat_t::default()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Kind::Dir { path, .. } => {
|
||||||
|
let md = path.metadata().ok()?;
|
||||||
|
Some(__wasi_filestat_t {
|
||||||
|
st_filetype: host_file_type_to_wasi_file_type(md.file_type()),
|
||||||
|
st_size: md.len(),
|
||||||
|
st_atim: md
|
||||||
|
.accessed()
|
||||||
|
.ok()?
|
||||||
|
.duration_since(SystemTime::UNIX_EPOCH)
|
||||||
|
.ok()?
|
||||||
|
.as_nanos() as u64,
|
||||||
|
st_mtim: md
|
||||||
|
.modified()
|
||||||
|
.ok()?
|
||||||
|
.duration_since(SystemTime::UNIX_EPOCH)
|
||||||
|
.ok()?
|
||||||
|
.as_nanos() as u64,
|
||||||
|
st_ctim: md
|
||||||
|
.created()
|
||||||
|
.ok()?
|
||||||
|
.duration_since(SystemTime::UNIX_EPOCH)
|
||||||
|
.ok()?
|
||||||
|
.as_nanos() as u64,
|
||||||
|
..__wasi_filestat_t::default()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -9,7 +9,8 @@ use self::types::*;
|
|||||||
use crate::{
|
use crate::{
|
||||||
ptr::{Array, WasmPtr},
|
ptr::{Array, WasmPtr},
|
||||||
state::{
|
state::{
|
||||||
host_file_type_to_wasi_file_type, Fd, InodeVal, Kind, WasiFile, WasiState, MAX_SYMLINKS,
|
get_stat_for_kind, host_file_type_to_wasi_file_type, Fd, InodeVal, Kind, WasiFile,
|
||||||
|
WasiState, MAX_SYMLINKS,
|
||||||
},
|
},
|
||||||
ExitCode,
|
ExitCode,
|
||||||
};
|
};
|
||||||
@ -1082,7 +1083,7 @@ pub fn path_create_directory(
|
|||||||
entries: Default::default(),
|
entries: Default::default(),
|
||||||
};
|
};
|
||||||
let new_inode = state.fs.inodes.insert(InodeVal {
|
let new_inode = state.fs.inodes.insert(InodeVal {
|
||||||
stat: __wasi_filestat_t::default(),
|
stat: wasi_try!(get_stat_for_kind(&kind).ok_or(__WASI_EIO)),
|
||||||
is_preopened: false,
|
is_preopened: false,
|
||||||
name: path_vec[0].clone(),
|
name: path_vec[0].clone(),
|
||||||
kind,
|
kind,
|
||||||
@ -1226,10 +1227,7 @@ pub fn path_filestat_get(
|
|||||||
}
|
}
|
||||||
let final_path_metadata =
|
let final_path_metadata =
|
||||||
wasi_try!(cumulative_path.metadata().map_err(|_| __WASI_EIO));
|
wasi_try!(cumulative_path.metadata().map_err(|_| __WASI_EIO));
|
||||||
__wasi_filestat_t {
|
wasi_try!(get_stat_for_kind(&state.fs.inodes[inode].kind).ok_or(__WASI_EIO))
|
||||||
st_filetype: host_file_type_to_wasi_file_type(final_path_metadata.file_type()),
|
|
||||||
..Default::default()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
@ -1533,7 +1531,7 @@ pub fn path_open(
|
|||||||
|
|
||||||
// record lazily loaded or newly created fd
|
// record lazily loaded or newly created fd
|
||||||
let new_inode = state.fs.inodes.insert(InodeVal {
|
let new_inode = state.fs.inodes.insert(InodeVal {
|
||||||
stat: __wasi_filestat_t::default(),
|
stat: wasi_try!(get_stat_for_kind(&kind).ok_or(__WASI_EIO)),
|
||||||
is_preopened: false,
|
is_preopened: false,
|
||||||
name: file_name.clone(),
|
name: file_name.clone(),
|
||||||
kind,
|
kind,
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#[test]
|
#[test]
|
||||||
#[ignore]
|
|
||||||
fn test_file_metadata() {
|
fn test_file_metadata() {
|
||||||
assert_wasi_output!(
|
assert_wasi_output!(
|
||||||
"../../wasitests/file_metadata.wasm",
|
"../../wasitests/file_metadata.wasm",
|
||||||
|
Binary file not shown.
@ -1,2 +1,3 @@
|
|||||||
is dir: false
|
is dir: false
|
||||||
file info: FileType(FileType { mode: 33188 }) 419 Ok(SystemTime { tv_sec: 1558132188, tv_nsec: 545288295 }) Ok(SystemTime { tv_sec: 1558132188, tv_nsec: 545243056 }) Ok(SystemTime { tv_sec: 1558132191, tv_nsec: 359031112 })
|
filetype: false true false
|
||||||
|
file info: 491
|
||||||
|
@ -6,12 +6,12 @@ fn main() {
|
|||||||
fs::File::open("wasitests/file_metadata.rs").expect("could not find src file");
|
fs::File::open("wasitests/file_metadata.rs").expect("could not find src file");
|
||||||
let md = this_file.metadata().unwrap();
|
let md = this_file.metadata().unwrap();
|
||||||
println!("is dir: {}", md.is_dir());
|
println!("is dir: {}", md.is_dir());
|
||||||
|
let filetype = md.file_type();
|
||||||
println!(
|
println!(
|
||||||
"file info: {:?} {} {:?} {:?} {:?}",
|
"filetype: {} {} {}",
|
||||||
md.file_type(),
|
filetype.is_dir(),
|
||||||
md.len(),
|
filetype.is_file(),
|
||||||
md.modified(),
|
filetype.is_symlink()
|
||||||
md.created(),
|
|
||||||
md.accessed()
|
|
||||||
);
|
);
|
||||||
|
println!("file info: {} {} {}", md.len(), md.modified(), md.created());
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
@ -1,2 +1 @@
|
|||||||
file_metadata
|
|
||||||
create_dir
|
create_dir
|
||||||
|
Loading…
Reference in New Issue
Block a user