mirror of
https://github.com/extism/extism.git
synced 2026-01-10 06:18:00 -05:00
Since it's using a read-only path, we should provide some information about how to use a read/write path to make this program run without failing.
37 lines
1.2 KiB
Rust
37 lines
1.2 KiB
Rust
use extism::*;
|
|
fn main() {
|
|
let url = Wasm::file("../wasm/read_write.wasm");
|
|
let manifest = Manifest::new([url])
|
|
// This will fail because we're using a readonly path (specified with the `ro:` prefix)
|
|
// to overwrite the data file, remove `ro:` from the path on the following line
|
|
.with_allowed_path("ro:src/tests/data".to_string(), "/data")
|
|
.with_config_key("path", "/data/data.txt");
|
|
|
|
let mut plugin = PluginBuilder::new(manifest)
|
|
.with_wasi(true)
|
|
.build()
|
|
.unwrap();
|
|
|
|
println!("trying to read file: ");
|
|
|
|
let res = plugin.call::<&str, &str>("try_read", "").unwrap();
|
|
|
|
println!("{:?}", res);
|
|
|
|
println!("-----------------------------------------------------");
|
|
|
|
// If the allowed path is readonly then writing back to the file should fail
|
|
println!("trying to write file: ");
|
|
let line = format!(
|
|
"Hello World at {:?}\n",
|
|
std::time::SystemTime::now()
|
|
.duration_since(std::time::SystemTime::UNIX_EPOCH)
|
|
.unwrap()
|
|
);
|
|
let res2 = plugin.call::<&str, &str>("try_write", &line).unwrap();
|
|
|
|
println!("{:?}", res2);
|
|
|
|
println!("done!");
|
|
}
|