wasmer/tests/wasi_test_resources/writing.rs
2020-04-15 16:31:05 -07:00

42 lines
1.1 KiB
Rust

// WASI:
// mapdir: act1:tests/wasi_test_resources/test_fs/hamlet/act1
// mapdir: act2:tests/wasi_test_resources/test_fs/hamlet/act2
// mapdir: act1-again:tests/wasi_test_resources/test_fs/hamlet/act1
use std::fs;
use std::io::Write;
pub const BYTE_STR: &'static [u8] = b"abcdefghijklmnopqrstuvwxyz";
fn main() {
#[cfg(not(target_os = "wasi"))]
do_logic_on_path(
"tests/wasi_test_resources/test_fs/hamlet/act1/abc",
"tests/wasi_test_resources/test_fs/hamlet/act1/abc",
);
#[cfg(target_os = "wasi")]
do_logic_on_path("/act1/abc", "act1-again/abc");
}
fn do_logic_on_path(path: &'static str, alt_path: &'static str) {
{
let mut f = fs::OpenOptions::new()
.create_new(true)
.write(true)
.open(path)
.unwrap();
f.write_all(BYTE_STR).unwrap();
}
println!("{}", fs::read_to_string(alt_path).unwrap());
fs::remove_file(path).unwrap();
let file_path = std::path::Path::new(path);
if file_path.exists() {
println!("file is here");
} else {
println!("file is gone")
}
}