feat: add early binary detection and prevent duplicate metadata saving

Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-08-16 14:23:28 -03:00
parent 9fa0dedb42
commit 389bb59531
3 changed files with 24 additions and 1 deletions

View File

@@ -22,6 +22,7 @@ pub struct BinaryMetaPlugin {
meta_name: String,
buffer: Vec<u8>,
max_buffer_size: usize,
saved_during_io: bool,
item_id: Option<i64>,
conn: Option<*mut Connection>,
}
@@ -32,6 +33,7 @@ impl BinaryMetaPlugin {
meta_name: "binary".to_string(),
buffer: Vec::new(),
max_buffer_size: 4096, // 4KB
saved_during_io: false,
item_id: None,
conn: None,
}
@@ -49,6 +51,12 @@ impl MetaPlugin for BinaryMetaPlugin {
}
fn finalize(&mut self) -> io::Result<String> {
// If we already saved during IO, don't save again
if self.saved_during_io {
// Return the current value to avoid errors, but it won't be saved again
let is_binary = is_binary(&self.buffer);
return Ok(if is_binary { "true".to_string() } else { "false".to_string() });
}
let is_binary = is_binary(&self.buffer);
Ok(if is_binary { "true".to_string() } else { "false".to_string() })
}