From a499483520cce38efadcb64a3674fb072e2f9cc6 Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Wed, 3 Dec 2025 00:54:27 -0500 Subject: [PATCH] fix the commit handling again --- src/math_app.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/math_app.rs b/src/math_app.rs index 2f3cb58..237dbbc 100644 --- a/src/math_app.rs +++ b/src/math_app.rs @@ -159,8 +159,13 @@ impl MathApp { let data = get_localstorage().get_item(DATA_NAME).ok()??; let (commit, cached_data) = crate::misc::hashed_storage_read(&data)?; + // Build expected commit hash + let commit_bytes = build::SHORT_COMMIT.as_bytes(); + let mut expected_commit: crate::misc::HashBytes = [0u8; crate::misc::HASH_LENGTH]; + let len = commit_bytes.len().min(crate::misc::HASH_LENGTH); + expected_commit[..len].copy_from_slice(&commit_bytes[..len]); - if commit == unsafe { std::mem::transmute::<&str, crate::misc::HashBytes>(build::SHORT_COMMIT) } { + if commit == expected_commit { tracing::info!("Reading decompression cache. Bytes: {}", cached_data.len()); return Some(cached_data.to_vec()); } else { @@ -176,10 +181,14 @@ impl MathApp { // TODO: stabilize FunctionManager serialize so it can persist across builds let (commit, func_data) = crate::misc::hashed_storage_read(&data)?; - let func_data: &[u8] = &func_data; + // Build expected commit hash + let commit_bytes = build::SHORT_COMMIT.as_bytes(); + let mut expected_commit: crate::misc::HashBytes = [0u8; crate::misc::HASH_LENGTH]; + let len = commit_bytes.len().min(crate::misc::HASH_LENGTH); + expected_commit[..len].copy_from_slice(&commit_bytes[..len]); - if commit == unsafe { std::mem::transmute::<&str, &[u8]>(build::SHORT_COMMIT) } { + if commit == expected_commit { tracing::info!("Reading previous function data"); let function_manager: FunctionManager = bincode::deserialize(&func_data).ok()?; return Some(function_manager);