diff --git a/lib/cache/Cargo.toml b/lib/cache/Cargo.toml index 8c36e61ebba..b313d6df924 100644 --- a/lib/cache/Cargo.toml +++ b/lib/cache/Cargo.toml @@ -20,6 +20,7 @@ blake3 = "1.0" criterion = "0.3" tempfile = "3.4.0" rand = "0.8.3" +wasmer = { path = "../api", version = "=3.3.0", default-features = false, features = ["sys", "cranelift"] } wasmer-compiler-singlepass = { path = "../compiler-singlepass", version = "=3.3.0" } [features] @@ -28,4 +29,4 @@ filesystem = [] blake3-pure = ["blake3/pure"] [package.metadata.docs.rs] -features = ["wasmer/sys"] \ No newline at end of file +features = ["wasmer/sys"] diff --git a/lib/cache/src/filesystem.rs b/lib/cache/src/filesystem.rs index 237390c61cc..2a0841b061c 100644 --- a/lib/cache/src/filesystem.rs +++ b/lib/cache/src/filesystem.rs @@ -103,7 +103,7 @@ impl Cache for FileSystemCache { key.to_string() }; let path = self.path.join(filename); - let ret = Module::deserialize_from_file(engine, path.clone()); + let ret = Module::deserialize_from_file_checked(engine, path.clone()); if ret.is_err() { // If an error occurs while deserializing then we can not trust it anymore // so delete the cache file @@ -127,3 +127,25 @@ impl Cache for FileSystemCache { Ok(()) } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_fs_cache() { + let dir = tempfile::tempdir().unwrap(); + + let mut cache = FileSystemCache::new(dir.path()).unwrap(); + + let engine = wasmer::Engine::default(); + + let bytes = include_bytes!("../../wasi/tests/envvar.wasm"); + + let module = Module::from_binary(&engine, bytes).unwrap(); + let key = Hash::generate(bytes); + + cache.store(key, &module).unwrap(); + let _restored = unsafe { cache.load(&engine, key).unwrap() }; + } +}