fix: remove duplicate metadata processing in MagicFileMetaPlugin
Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
This commit is contained in:
@@ -9,7 +9,7 @@ use crate::meta_plugin::MetaPlugin;
|
||||
pub struct MagicFileMetaPlugin {
|
||||
buffer: Vec<u8>,
|
||||
max_buffer_size: usize,
|
||||
is_saved: bool,
|
||||
is_finalized: bool,
|
||||
cookie: Option<Cookie>,
|
||||
base: crate::meta_plugin::BaseMetaPlugin,
|
||||
}
|
||||
@@ -51,7 +51,7 @@ impl MagicFileMetaPlugin {
|
||||
MagicFileMetaPlugin {
|
||||
buffer: Vec::new(),
|
||||
max_buffer_size,
|
||||
is_saved: false,
|
||||
is_finalized: false,
|
||||
cookie: None,
|
||||
base,
|
||||
}
|
||||
@@ -119,6 +119,13 @@ impl MagicFileMetaPlugin {
|
||||
}
|
||||
|
||||
impl MetaPlugin for MagicFileMetaPlugin {
|
||||
fn is_finalized(&self) -> bool {
|
||||
self.is_finalized
|
||||
}
|
||||
|
||||
fn set_finalized(&mut self, finalized: bool) {
|
||||
self.is_finalized = finalized;
|
||||
}
|
||||
|
||||
fn initialize(&mut self) -> crate::meta_plugin::MetaPluginResponse {
|
||||
// Initialize the magic cookie once
|
||||
@@ -146,8 +153,19 @@ impl MetaPlugin for MagicFileMetaPlugin {
|
||||
}
|
||||
|
||||
fn finalize(&mut self) -> crate::meta_plugin::MetaPluginResponse {
|
||||
// If already finalized, don't process again
|
||||
if self.is_finalized {
|
||||
return crate::meta_plugin::MetaPluginResponse {
|
||||
metadata: Vec::new(),
|
||||
is_finalized: true,
|
||||
};
|
||||
}
|
||||
|
||||
let metadata = self.process_magic_types();
|
||||
|
||||
// Mark as finalized
|
||||
self.is_finalized = true;
|
||||
|
||||
crate::meta_plugin::MetaPluginResponse {
|
||||
metadata,
|
||||
is_finalized: true,
|
||||
@@ -155,6 +173,14 @@ impl MetaPlugin for MagicFileMetaPlugin {
|
||||
}
|
||||
|
||||
fn update(&mut self, data: &[u8]) -> crate::meta_plugin::MetaPluginResponse {
|
||||
// If already finalized, don't process more data
|
||||
if self.is_finalized {
|
||||
return crate::meta_plugin::MetaPluginResponse {
|
||||
metadata: Vec::new(),
|
||||
is_finalized: true,
|
||||
};
|
||||
}
|
||||
|
||||
let mut metadata = Vec::new();
|
||||
|
||||
// Only collect up to max_buffer_size
|
||||
@@ -166,6 +192,9 @@ impl MetaPlugin for MagicFileMetaPlugin {
|
||||
// Check if we've reached our buffer limit and return metadata
|
||||
if self.buffer.len() >= self.max_buffer_size {
|
||||
metadata = self.process_magic_types();
|
||||
|
||||
// Mark as finalized when we've processed enough data
|
||||
self.is_finalized = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user