From 9bc286c49e4699d5cf7bbf74174f93498af5a921 Mon Sep 17 00:00:00 2001 From: Johnathan Sharratt Date: Mon, 8 Jan 2024 21:42:21 +1100 Subject: [PATCH] Fixed an issue where the caching compiled modules were not saving properly --- .../src/runtime/module_cache/filesystem.rs | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/lib/wasix/src/runtime/module_cache/filesystem.rs b/lib/wasix/src/runtime/module_cache/filesystem.rs index a2e60f549bc..30db6f78451 100644 --- a/lib/wasix/src/runtime/module_cache/filesystem.rs +++ b/lib/wasix/src/runtime/module_cache/filesystem.rs @@ -63,19 +63,19 @@ impl ModuleCache for FileSystemCache { } Err(e) => { tracing::debug!( - %key, - path=%path.display(), - error=&e as &dyn std::error::Error, - "Deleting the cache file because the artifact couldn't be deserialized", - ); + %key, + path=%path.display(), + error=&e as &dyn std::error::Error, + "Deleting the cache file because the artifact couldn't be deserialized", + ); if let Err(e) = std::fs::remove_file(&path) { tracing::warn!( - %key, - path=%path.display(), - error=&e as &dyn std::error::Error, - "Unable to remove the corrupted cache file", - ); + %key, + path=%path.display(), + error=&e as &dyn std::error::Error, + "Unable to remove the corrupted cache file", + ); } Err(e) @@ -131,10 +131,11 @@ impl ModuleCache for FileSystemCache { .await .unwrap()?; - if let Err(error) = tokio::io::BufWriter::new(&mut file) - .write_all(&serialized) - .await - { + let mut writer = tokio::io::BufWriter::new(&mut file); + if let Err(error) = writer.write_all(&serialized).await { + return Err(CacheError::FileWrite { path, error }); + } + if let Err(error) = writer.flush().await { return Err(CacheError::FileWrite { path, error }); }