mirror of
https://github.com/fluencelabs/wasmer
synced 2024-12-05 02:20:19 +00:00
42 lines
1.1 KiB
Rust
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")
|
|
}
|
|
}
|