2019-07-17 21:00:51 +00:00
|
|
|
// Args:
|
|
|
|
// mapdir: act1:wasitests/test_fs/hamlet/act1
|
|
|
|
// mapdir: act2:wasitests/test_fs/hamlet/act2
|
|
|
|
// mapdir: act1-again:wasitests/test_fs/hamlet/act1
|
|
|
|
|
|
|
|
use std::fs;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
// just cheat in this test because there is no comparison for native
|
|
|
|
#[cfg(not(target_os = "wasi"))]
|
|
|
|
let results = {
|
2019-07-17 22:32:47 +00:00
|
|
|
let start = vec!["\"/act1\"", "\"/act1-again\"", "\"/act2\""];
|
2019-07-17 21:00:51 +00:00
|
|
|
|
|
|
|
let mut out = vec![];
|
|
|
|
for _ in 0..4 {
|
|
|
|
for path_str in &start {
|
|
|
|
out.push(path_str.to_string());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-19 00:14:01 +00:00
|
|
|
out.push("ROOT IS SAFE".to_string());
|
2019-07-17 21:00:51 +00:00
|
|
|
out
|
|
|
|
};
|
|
|
|
|
|
|
|
#[cfg(target_os = "wasi")]
|
|
|
|
let results = {
|
|
|
|
let mut out = vec![];
|
|
|
|
|
|
|
|
let read_dir = fs::read_dir("/").unwrap();
|
|
|
|
for entry in read_dir {
|
|
|
|
out.push(format!("{:?}", entry.unwrap().path()))
|
|
|
|
}
|
|
|
|
let read_dir = fs::read_dir("act1/..").unwrap();
|
|
|
|
for entry in read_dir {
|
|
|
|
out.push(format!("{:?}", entry.unwrap().path()))
|
|
|
|
}
|
|
|
|
let read_dir = fs::read_dir("act1/../../..").unwrap();
|
|
|
|
for entry in read_dir {
|
|
|
|
out.push(format!("{:?}", entry.unwrap().path()))
|
|
|
|
}
|
|
|
|
let read_dir = fs::read_dir("act1/../../act2/../act1/../../../").unwrap();
|
|
|
|
for entry in read_dir {
|
|
|
|
out.push(format!("{:?}", entry.unwrap().path()))
|
|
|
|
}
|
2019-07-19 00:14:01 +00:00
|
|
|
let f = fs::OpenOptions::new().write(true).open("/abc");
|
|
|
|
|
|
|
|
if f.is_ok() {
|
|
|
|
out.push("ROOT IS NOT SAFE".to_string());
|
|
|
|
} else {
|
|
|
|
out.push("ROOT IS SAFE".to_string());
|
|
|
|
}
|
2019-07-17 21:00:51 +00:00
|
|
|
|
|
|
|
out
|
|
|
|
};
|
|
|
|
|
|
|
|
for result in results {
|
|
|
|
println!("{}", result);
|
|
|
|
}
|
|
|
|
}
|