From 8e7f515e4c80d2dbca49eb407d038e135c102e96 Mon Sep 17 00:00:00 2001 From: Vaughn Dice Date: Wed, 25 Oct 2023 11:09:39 -0600 Subject: [PATCH] feat(loader/cache): add data dir fallback if wasm layer not found Signed-off-by: Vaughn Dice --- crates/loader/src/cache.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/loader/src/cache.rs b/crates/loader/src/cache.rs index 221b760fa2..1cc55eed9e 100644 --- a/crates/loader/src/cache.rs +++ b/crates/loader/src/cache.rs @@ -50,7 +50,14 @@ impl Cache { /// Return the path to a wasm file given its digest. pub fn wasm_file(&self, digest: impl AsRef) -> Result { - let path = self.wasm_path(&digest); + // Check the expected wasm directory first; else check the data directory as a fallback. + // (Layers with unknown media types are currently saved to the data directory in client.pull()) + // This adds a bit of futureproofing for fetching wasm layers with different/updated media types + // (see WASM_LAYER_MEDIA_TYPE, which is subject to change in future versions). + let mut path = self.wasm_path(&digest); + if !path.exists() { + path = self.data_path(&digest); + } ensure!( path.exists(), "cannot find wasm file for digest {}",