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)
|
// Convert raw pointer back to reference (unsafe)
|
||||||
let conn_ref = unsafe { &*conn };
|
let conn_ref = unsafe { &*conn };
|
||||||
|
|
||||||
// Save file type
|
// Only save MIME type since that's what's mapped in the config
|
||||||
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
|
|
||||||
if let Ok(mime_type) = self.get_magic_result(CookieFlags::MIME_TYPE) {
|
if let Ok(mime_type) = self.get_magic_result(CookieFlags::MIME_TYPE) {
|
||||||
if !mime_type.is_empty() {
|
if !mime_type.is_empty() {
|
||||||
let _ = output_metadata(conn_ref, item_id, "mime_type", mime_type, &self.output_names);
|
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;
|
self.is_saved = true;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -49,19 +49,8 @@ impl MetaPlugin for BinaryMetaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn finalize(&mut self) -> Result<()> {
|
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
|
||||||
Ok(())
|
if !self.is_saved {
|
||||||
}
|
|
||||||
|
|
||||||
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 {
|
|
||||||
if let (Some(conn), Some(item_id)) = (self.conn, self.item_id) {
|
if let (Some(conn), Some(item_id)) = (self.conn, self.item_id) {
|
||||||
// Convert raw pointer back to reference (unsafe)
|
// Convert raw pointer back to reference (unsafe)
|
||||||
let conn_ref = unsafe { &*conn };
|
let conn_ref = unsafe { &*conn };
|
||||||
@@ -74,6 +63,15 @@ impl MetaPlugin for BinaryMetaPlugin {
|
|||||||
self.is_saved = true;
|
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