fix: correct magic file type and mime encoding detection

Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-08-18 08:50:01 -03:00
parent 1e4e039672
commit 1b6ff44312

View File

@@ -28,7 +28,12 @@ impl MagicFileMetaPlugin {
}
fn get_magic_result(&self, flags: CookieFlags) -> io::Result<String> {
if let Some(ref cookie) = self.cookie {
// Create a new cookie with the specific flags for this request
let cookie = Cookie::open(flags)
.map_err(|e| io::Error::new(io::ErrorKind::Other, format!("Failed to open magic cookie: {}", e)))?;
cookie.load(&[] as &[&str])
.map_err(|e| io::Error::new(io::ErrorKind::Other, format!("Failed to load magic database: {}", e)))?;
let result = cookie.buffer(&self.buffer)
.map_err(|e| io::Error::new(io::ErrorKind::Other, format!("Failed to analyze buffer: {}", e)))?;
@@ -45,12 +50,6 @@ impl MagicFileMetaPlugin {
};
Ok(cleaned.to_string())
} else {
Err(io::Error::new(
io::ErrorKind::Other,
"Magic cookie not initialized".to_string(),
))
}
}
fn save_all_magic_metadata(&mut self) -> Result<()> {
@@ -122,13 +121,6 @@ impl MetaPlugin for MagicFileMetaPlugin {
// Store raw pointer to connection - unsafe but necessary for this design
self.conn = Some(conn as *const _ as *mut Connection);
// Initialize magic cookie with flags for comprehensive detection
let cookie = Cookie::open(CookieFlags::MIME_TYPE | CookieFlags::MIME_ENCODING | CookieFlags::MIME)
.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(())
}