From 2a16edcbe7d232ec0d432f291f61fc584e4ad4ec Mon Sep 17 00:00:00 2001 From: Andrew Phillips Date: Mon, 18 Aug 2025 11:08:48 -0300 Subject: [PATCH] fix: remove unused magic_file metadata outputs and fix binary detection timing Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) --- src/meta_plugin/magic.rs | 16 +--------------- src/meta_plugin/system.rs | 30 ++++++++++++++---------------- 2 files changed, 15 insertions(+), 31 deletions(-) diff --git a/src/meta_plugin/magic.rs b/src/meta_plugin/magic.rs index 64553db..94a4825 100644 --- a/src/meta_plugin/magic.rs +++ b/src/meta_plugin/magic.rs @@ -61,27 +61,13 @@ impl MagicFileMetaPlugin { // Convert raw pointer back to reference (unsafe) let conn_ref = unsafe { &*conn }; - // Save file type - if let Ok(file_type) = self.get_magic_result(CookieFlags::empty()) { - if !file_type.is_empty() { - let _ = output_metadata(conn_ref, item_id, "file_type", file_type, &self.output_names); - } - } - - // Save MIME type + // Only save MIME type since that's what's mapped in the config if let Ok(mime_type) = self.get_magic_result(CookieFlags::MIME_TYPE) { if !mime_type.is_empty() { let _ = output_metadata(conn_ref, item_id, "mime_type", mime_type, &self.output_names); } } - // Save MIME encoding - if let Ok(mime_encoding) = self.get_magic_result(CookieFlags::MIME_ENCODING) { - if !mime_encoding.is_empty() { - let _ = output_metadata(conn_ref, item_id, "mime_encoding", mime_encoding, &self.output_names); - } - } - self.is_saved = true; } Ok(()) diff --git a/src/meta_plugin/system.rs b/src/meta_plugin/system.rs index e12b4b1..9d43ff3 100644 --- a/src/meta_plugin/system.rs +++ b/src/meta_plugin/system.rs @@ -49,7 +49,20 @@ impl MetaPlugin for BinaryMetaPlugin { } fn finalize(&mut self) -> Result<()> { - // Since we save during initialize() or update(), return Ok to avoid duplicate saves + // Save the binary detection result when finalizing, after all data has been collected + if !self.is_saved { + if let (Some(conn), Some(item_id)) = (self.conn, self.item_id) { + // Convert raw pointer back to reference (unsafe) + let conn_ref = unsafe { &*conn }; + let is_binary = is_binary(&self.buffer); + let value = if is_binary { "true".to_string() } else { "false".to_string() }; + + // Save to database immediately using central output handler + let _ = output_metadata(conn_ref, item_id, &self.meta_name, value, &self.output_names); + + self.is_saved = true; + } + } Ok(()) } @@ -59,21 +72,6 @@ impl MetaPlugin for BinaryMetaPlugin { if remaining_capacity > 0 { let bytes_to_copy = std::cmp::min(data.len(), remaining_capacity); self.buffer.extend_from_slice(&data[..bytes_to_copy]); - - // Check if we've reached our buffer limit and save if so - if self.buffer.len() >= self.max_buffer_size && !self.is_saved { - if let (Some(conn), Some(item_id)) = (self.conn, self.item_id) { - // Convert raw pointer back to reference (unsafe) - let conn_ref = unsafe { &*conn }; - let is_binary = is_binary(&self.buffer); - let value = if is_binary { "true".to_string() } else { "false".to_string() }; - - // Save to database immediately using central output handler - let _ = output_metadata(conn_ref, item_id, &self.meta_name, value, &self.output_names); - - self.is_saved = true; - } - } } }