fix: remove unused magic_file metadata outputs and fix binary detection timing
Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
This commit is contained in:
@@ -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(())
|
||||
|
||||
@@ -49,19 +49,8 @@ impl MetaPlugin for BinaryMetaPlugin {
|
||||
}
|
||||
|
||||
fn finalize(&mut self) -> Result<()> {
|
||||
// Since we save during initialize() or update(), return Ok to avoid duplicate saves
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn update(&mut self, data: &[u8]) {
|
||||
// Only collect up to max_buffer_size
|
||||
let remaining_capacity = self.max_buffer_size.saturating_sub(self.buffer.len());
|
||||
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 {
|
||||
// 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 };
|
||||
@@ -74,6 +63,15 @@ impl MetaPlugin for BinaryMetaPlugin {
|
||||
self.is_saved = true;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn update(&mut self, data: &[u8]) {
|
||||
// Only collect up to max_buffer_size
|
||||
let remaining_capacity = self.max_buffer_size.saturating_sub(self.buffer.len());
|
||||
if remaining_capacity > 0 {
|
||||
let bytes_to_copy = std::cmp::min(data.len(), remaining_capacity);
|
||||
self.buffer.extend_from_slice(&data[..bytes_to_copy]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user