refactor: remove connection storage from plugin structs and pass as argument
Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
This commit is contained in:
@@ -24,7 +24,6 @@ pub struct BinaryMetaPlugin {
|
||||
max_buffer_size: usize,
|
||||
is_saved: bool,
|
||||
item_id: Option<i64>,
|
||||
conn: Option<*mut Connection>,
|
||||
output_names: std::collections::HashMap<String, String>,
|
||||
}
|
||||
|
||||
@@ -36,7 +35,6 @@ impl BinaryMetaPlugin {
|
||||
max_buffer_size: 4096, // 4KB
|
||||
is_saved: false,
|
||||
item_id: None,
|
||||
conn: None,
|
||||
output_names: std::collections::HashMap::new(),
|
||||
}
|
||||
}
|
||||
@@ -48,17 +46,15 @@ impl MetaPlugin for BinaryMetaPlugin {
|
||||
true
|
||||
}
|
||||
|
||||
fn finalize(&mut self) -> Result<()> {
|
||||
fn finalize(&mut self, conn: &Connection) -> Result<()> {
|
||||
// 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 };
|
||||
if let Some(item_id) = self.item_id {
|
||||
let is_binary = is_binary(&self.buffer);
|
||||
let value = if is_binary { "true".to_string() } else { "false".to_string() };
|
||||
|
||||
// Save to database immediately using central output handler
|
||||
let _ = output_metadata(conn_ref, item_id, &self.meta_name, value, &self.output_names);
|
||||
let _ = output_metadata(conn, item_id, &self.meta_name, value, &self.output_names);
|
||||
|
||||
self.is_saved = true;
|
||||
}
|
||||
@@ -66,7 +62,7 @@ impl MetaPlugin for BinaryMetaPlugin {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn update(&mut self, data: &[u8]) {
|
||||
fn update(&mut self, data: &[u8], _conn: &Connection) {
|
||||
// Only collect up to max_buffer_size
|
||||
let remaining_capacity = self.max_buffer_size.saturating_sub(self.buffer.len());
|
||||
if remaining_capacity > 0 {
|
||||
@@ -79,10 +75,8 @@ impl MetaPlugin for BinaryMetaPlugin {
|
||||
self.meta_name.clone()
|
||||
}
|
||||
|
||||
fn initialize(&mut self, conn: &Connection, item_id: i64) -> Result<()> {
|
||||
fn initialize(&mut self, _conn: &Connection, item_id: i64) -> Result<()> {
|
||||
self.item_id = Some(item_id);
|
||||
// Store raw pointer to connection - unsafe but necessary for this design
|
||||
self.conn = Some(conn as *const _ as *mut Connection);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -125,12 +119,12 @@ impl MetaPlugin for CwdMetaPlugin {
|
||||
true
|
||||
}
|
||||
|
||||
fn finalize(&mut self) -> Result<()> {
|
||||
fn finalize(&mut self, _conn: &Connection) -> Result<()> {
|
||||
// Since we save during initialize(), return Ok to avoid duplicate saves
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn update(&mut self, _data: &[u8]) {
|
||||
fn update(&mut self, _data: &[u8], _conn: &Connection) {
|
||||
// No update needed
|
||||
}
|
||||
|
||||
@@ -187,12 +181,12 @@ impl MetaPlugin for UidMetaPlugin {
|
||||
true
|
||||
}
|
||||
|
||||
fn finalize(&mut self) -> Result<()> {
|
||||
fn finalize(&mut self, _conn: &Connection) -> Result<()> {
|
||||
// Since we save during initialize(), return Ok to avoid duplicate saves
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn update(&mut self, _data: &[u8]) {
|
||||
fn update(&mut self, _data: &[u8], _conn: &Connection) {
|
||||
// No update needed
|
||||
}
|
||||
|
||||
@@ -228,12 +222,12 @@ impl MetaPlugin for UserMetaPlugin {
|
||||
true
|
||||
}
|
||||
|
||||
fn finalize(&mut self) -> Result<()> {
|
||||
fn finalize(&mut self, _conn: &Connection) -> Result<()> {
|
||||
// Since we save during initialize(), return Ok to avoid duplicate saves
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn update(&mut self, _data: &[u8]) {
|
||||
fn update(&mut self, _data: &[u8], _conn: &Connection) {
|
||||
// No update needed
|
||||
}
|
||||
|
||||
@@ -272,12 +266,12 @@ impl MetaPlugin for GidMetaPlugin {
|
||||
true
|
||||
}
|
||||
|
||||
fn finalize(&mut self) -> Result<()> {
|
||||
fn finalize(&mut self, _conn: &Connection) -> Result<()> {
|
||||
// Since we save during initialize(), return Ok to avoid duplicate saves
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn update(&mut self, _data: &[u8]) {
|
||||
fn update(&mut self, _data: &[u8], _conn: &Connection) {
|
||||
// No update needed
|
||||
}
|
||||
|
||||
@@ -313,12 +307,12 @@ impl MetaPlugin for GroupMetaPlugin {
|
||||
true
|
||||
}
|
||||
|
||||
fn finalize(&mut self) -> Result<()> {
|
||||
fn finalize(&mut self, _conn: &Connection) -> Result<()> {
|
||||
// Since we save during initialize(), return Ok to avoid duplicate saves
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn update(&mut self, _data: &[u8]) {
|
||||
fn update(&mut self, _data: &[u8], _conn: &Connection) {
|
||||
// No update needed
|
||||
}
|
||||
|
||||
@@ -357,12 +351,12 @@ impl MetaPlugin for ShellMetaPlugin {
|
||||
true
|
||||
}
|
||||
|
||||
fn finalize(&mut self) -> Result<()> {
|
||||
fn finalize(&mut self, _conn: &Connection) -> Result<()> {
|
||||
// Since we save during initialize(), return Ok to avoid duplicate saves
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn update(&mut self, _data: &[u8]) {
|
||||
fn update(&mut self, _data: &[u8], _conn: &Connection) {
|
||||
// No update needed
|
||||
}
|
||||
|
||||
@@ -401,12 +395,12 @@ impl MetaPlugin for ShellPidMetaPlugin {
|
||||
true
|
||||
}
|
||||
|
||||
fn finalize(&mut self) -> Result<()> {
|
||||
fn finalize(&mut self, _conn: &Connection) -> Result<()> {
|
||||
// Since we save during initialize(), return Ok to avoid duplicate saves
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn update(&mut self, _data: &[u8]) {
|
||||
fn update(&mut self, _data: &[u8], _conn: &Connection) {
|
||||
// No update needed
|
||||
}
|
||||
|
||||
@@ -445,12 +439,12 @@ impl MetaPlugin for KeepPidMetaPlugin {
|
||||
true
|
||||
}
|
||||
|
||||
fn finalize(&mut self) -> Result<()> {
|
||||
fn finalize(&mut self, _conn: &Connection) -> Result<()> {
|
||||
// Since we save during initialize(), return Ok to avoid duplicate saves
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn update(&mut self, _data: &[u8]) {
|
||||
fn update(&mut self, _data: &[u8], _conn: &Connection) {
|
||||
// No update needed
|
||||
}
|
||||
|
||||
@@ -486,12 +480,12 @@ impl MetaPlugin for HostnameMetaPlugin {
|
||||
true
|
||||
}
|
||||
|
||||
fn finalize(&mut self) -> Result<()> {
|
||||
fn finalize(&mut self, _conn: &Connection) -> Result<()> {
|
||||
// Since we save during initialize(), return Ok to avoid duplicate saves
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn update(&mut self, _data: &[u8]) {
|
||||
fn update(&mut self, _data: &[u8], _conn: &Connection) {
|
||||
// No update needed for hostname
|
||||
}
|
||||
|
||||
@@ -530,12 +524,12 @@ impl MetaPlugin for FullHostnameMetaPlugin {
|
||||
true
|
||||
}
|
||||
|
||||
fn finalize(&mut self) -> Result<()> {
|
||||
fn finalize(&mut self, _conn: &Connection) -> Result<()> {
|
||||
// Since we save during initialize(), return Ok to avoid duplicate saves
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn update(&mut self, _data: &[u8]) {
|
||||
fn update(&mut self, _data: &[u8], _conn: &Connection) {
|
||||
// No update needed for full hostname
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user