feat: initialize cookie once and use set_flags for subsequent operations
Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
This commit is contained in:
@@ -28,11 +28,10 @@ impl MagicFileMetaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_magic_result(&self, flags: CookieFlags) -> io::Result<String> {
|
fn get_magic_result(&self, flags: CookieFlags) -> io::Result<String> {
|
||||||
// Create a new cookie with the specific flags for this request
|
// Use the existing cookie and just change flags
|
||||||
let cookie = Cookie::open(flags)
|
if let Some(cookie) = &self.cookie {
|
||||||
.map_err(|e| io::Error::new(io::ErrorKind::Other, format!("Failed to open magic cookie: {}", e)))?;
|
cookie.set_flags(flags)
|
||||||
cookie.load(&[] as &[&str])
|
.map_err(|e| io::Error::new(io::ErrorKind::Other, format!("Failed to set magic flags: {}", e)))?;
|
||||||
.map_err(|e| io::Error::new(io::ErrorKind::Other, format!("Failed to load magic database: {}", e)))?;
|
|
||||||
|
|
||||||
let result = cookie.buffer(&self.buffer)
|
let result = cookie.buffer(&self.buffer)
|
||||||
.map_err(|e| io::Error::new(io::ErrorKind::Other, format!("Failed to analyze buffer: {}", e)))?;
|
.map_err(|e| io::Error::new(io::ErrorKind::Other, format!("Failed to analyze buffer: {}", e)))?;
|
||||||
@@ -50,6 +49,9 @@ impl MagicFileMetaPlugin {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Ok(cleaned.to_string())
|
Ok(cleaned.to_string())
|
||||||
|
} else {
|
||||||
|
Err(io::Error::new(io::ErrorKind::Other, "Magic cookie not initialized"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn save_all_magic_metadata(&mut self) -> Result<()> {
|
fn save_all_magic_metadata(&mut self) -> Result<()> {
|
||||||
@@ -109,6 +111,13 @@ impl MetaPlugin for MagicFileMetaPlugin {
|
|||||||
// Store raw pointer to connection - unsafe but necessary for this design
|
// Store raw pointer to connection - unsafe but necessary for this design
|
||||||
self.conn = Some(conn as *const _ as *mut Connection);
|
self.conn = Some(conn as *const _ as *mut Connection);
|
||||||
|
|
||||||
|
// Initialize the magic cookie once
|
||||||
|
let cookie = Cookie::open(Default::default())
|
||||||
|
.map_err(|e| anyhow::anyhow!("Failed to open magic cookie: {}", e))?;
|
||||||
|
cookie.load(&[] as &[&str])
|
||||||
|
.map_err(|e| anyhow::anyhow!("Failed to load magic database: {}", e))?;
|
||||||
|
self.cookie = Some(cookie);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user