From 18a3f1b36e001eca84a9ce80ccbcfd25b207572a Mon Sep 17 00:00:00 2001 From: Andrew Phillips Date: Mon, 18 Aug 2025 09:20:07 -0300 Subject: [PATCH] feat: add sha256 hash metadata storage in finalize Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) --- src/meta_plugin/digest.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/meta_plugin/digest.rs b/src/meta_plugin/digest.rs index 9205bf4..f2586c1 100644 --- a/src/meta_plugin/digest.rs +++ b/src/meta_plugin/digest.rs @@ -1,6 +1,7 @@ use anyhow::Result; use sha2::{Digest, Sha256}; use std::time::Instant; +use rusqlite::Connection; use crate::meta_plugin::MetaPlugin; @@ -8,6 +9,8 @@ use crate::meta_plugin::MetaPlugin; pub struct DigestSha256MetaPlugin { hasher: Sha256, meta_name: String, + item_id: Option, + conn: Option<*mut Connection>, } impl DigestSha256MetaPlugin { @@ -15,6 +18,8 @@ impl DigestSha256MetaPlugin { DigestSha256MetaPlugin { hasher: Sha256::new(), meta_name: "digest_sha256".to_string(), + item_id: None, + conn: None, } } } @@ -24,7 +29,30 @@ impl MetaPlugin for DigestSha256MetaPlugin { true } + fn initialize(&mut self, conn: &Connection, item_id: i64) -> Result<()> { + self.item_id = Some(item_id); + // Store raw pointer to connection - unsafe but necessary for this design + self.conn = Some(conn as *const _ as *mut Connection); + Ok(()) + } + fn finalize(&mut self) -> Result<()> { + if let (Some(conn), Some(item_id)) = (self.conn, self.item_id) { + // Convert raw pointer back to reference (unsafe) + let conn_ref = unsafe { &*conn }; + + // Finalize the hash + let hash_result = self.hasher.finalize_reset(); + let hex_string = format!("{:x}", hash_result); + + // Save the hash as metadata + let meta = crate::db::Meta { + id: item_id, + name: self.meta_name.clone(), + value: hex_string, + }; + crate::db::store_meta(conn_ref, meta)?; + } Ok(()) }