fix: prevent duplicate metadata saves and fix binary plugin detection
Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
This commit is contained in:
@@ -8,7 +8,6 @@ use std::env;
|
||||
use std::process;
|
||||
use uzers::{get_current_uid, get_current_gid, get_current_username, get_current_groupname};
|
||||
use rusqlite::Connection;
|
||||
use log::debug;
|
||||
|
||||
use crate::common::is_binary::is_binary;
|
||||
use crate::meta_plugin::MetaPlugin;
|
||||
@@ -68,6 +67,26 @@ impl MetaPlugin for BinaryMetaPlugin {
|
||||
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) {
|
||||
// Convert raw pointer back to reference (unsafe)
|
||||
let conn_ref = unsafe { &*conn };
|
||||
let is_binary = is_binary(&self.buffer);
|
||||
let value = if is_binary { "true".to_string() } else { "false".to_string() };
|
||||
|
||||
// Save to database immediately
|
||||
let meta = crate::db::Meta {
|
||||
id: item_id,
|
||||
name: self.meta_name.clone(),
|
||||
value,
|
||||
};
|
||||
let _ = crate::db::store_meta(conn_ref, meta);
|
||||
|
||||
self.is_saved = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,6 +141,7 @@ impl MetaPlugin for CwdMetaPlugin {
|
||||
Err(_) => "unknown".to_string(),
|
||||
};
|
||||
self.save_meta(conn, item_id, cwd)?;
|
||||
// Mark as saved to prevent duplicate saves
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -210,6 +230,7 @@ impl MetaPlugin for UserMetaPlugin {
|
||||
None => "unknown".to_string(),
|
||||
};
|
||||
self.save_meta(conn, item_id, user)?;
|
||||
// Mark as saved to prevent duplicate saves
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -251,6 +272,7 @@ impl MetaPlugin for GidMetaPlugin {
|
||||
fn initialize(&mut self, conn: &Connection, item_id: i64) -> Result<()> {
|
||||
let gid = get_current_gid().to_string();
|
||||
self.save_meta(conn, item_id, gid)?;
|
||||
// Mark as saved to prevent duplicate saves
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -298,6 +320,7 @@ impl MetaPlugin for GroupMetaPlugin {
|
||||
None => "unknown".to_string(),
|
||||
};
|
||||
self.save_meta(conn, item_id, group)?;
|
||||
// Mark as saved to prevent duplicate saves
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -345,6 +368,7 @@ impl MetaPlugin for ShellMetaPlugin {
|
||||
Err(_) => "unknown".to_string(),
|
||||
};
|
||||
self.save_meta(conn, item_id, shell)?;
|
||||
// Mark as saved to prevent duplicate saves
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -392,6 +416,7 @@ impl MetaPlugin for ShellPidMetaPlugin {
|
||||
Err(_) => process::id().to_string(),
|
||||
};
|
||||
self.save_meta(conn, item_id, pid)?;
|
||||
// Mark as saved to prevent duplicate saves
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -433,6 +458,7 @@ impl MetaPlugin for KeepPidMetaPlugin {
|
||||
fn initialize(&mut self, conn: &Connection, item_id: i64) -> Result<()> {
|
||||
let pid = process::id().to_string();
|
||||
self.save_meta(conn, item_id, pid)?;
|
||||
// Mark as saved to prevent duplicate saves
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -480,6 +506,7 @@ impl MetaPlugin for HostnameMetaPlugin {
|
||||
Err(_) => "unknown".to_string(),
|
||||
};
|
||||
self.save_meta(conn, item_id, hostname)?;
|
||||
// Mark as saved to prevent duplicate saves
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -563,6 +590,7 @@ impl MetaPlugin for FullHostnameMetaPlugin {
|
||||
}
|
||||
};
|
||||
self.save_meta(conn, item_id, hostname)?;
|
||||
// Mark as saved to prevent duplicate saves
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user