Skip to content

Commit

Permalink
Add .module file extension
Browse files Browse the repository at this point in the history
  • Loading branch information
chipshort committed Oct 10, 2023
1 parent 36c8522 commit 1408043
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions packages/vm/src/modules/file_system_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,22 @@ impl FileSystemCache {
self.unchecked_modules = unchecked;
}

/// Returns the path to the serialized module with the given checksum.
fn module_file(&self, checksum: &Checksum) -> PathBuf {
let mut path = self.modules_path.clone();
path.push(checksum.to_hex());
path.set_extension("module");
path
}

/// Loads a serialized module from the file system and returns a module (i.e. artifact + store),
/// along with the size of the serialized module.
pub fn load(
&self,
checksum: &Checksum,
engine: &impl AsEngineRef,
) -> VmResult<Option<(Module, usize)>> {
let filename = checksum.to_hex();
let file_path = self.modules_path.join(filename);
let file_path = self.module_file(checksum);

let result = if self.unchecked_modules {
unsafe { Module::deserialize_from_file_unchecked(engine, &file_path) }
Expand Down Expand Up @@ -158,8 +165,7 @@ impl FileSystemCache {
mkdir_p(&self.modules_path)
.map_err(|_e| VmError::cache_err("Error creating modules directory"))?;

let filename = checksum.to_hex();
let path = self.modules_path.join(filename);
let path = self.module_file(checksum);
module
.serialize_to_file(&path)
.map_err(|e| VmError::cache_err(format!("Error writing module to disk: {e}")))?;
Expand All @@ -171,8 +177,7 @@ impl FileSystemCache {
///
/// Returns true if the file existed and false if the file did not exist.
pub fn remove(&mut self, checksum: &Checksum) -> VmResult<bool> {
let filename = checksum.to_hex();
let file_path = self.modules_path.join(filename);
let file_path = self.module_file(checksum);

if file_path.exists() {
fs::remove_file(file_path)
Expand Down Expand Up @@ -290,7 +295,7 @@ mod tests {
cache.store(&checksum, &module).unwrap();

let mut globber = glob::glob(&format!(
"{}/v8-wasmer5/**/{}",
"{}/v8-wasmer5/**/{}.module",
tmp_dir.path().to_string_lossy(),
checksum
))
Expand Down

0 comments on commit 1408043

Please sign in to comment.