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 std::process;
|
||||||
use uzers::{get_current_uid, get_current_gid, get_current_username, get_current_groupname};
|
use uzers::{get_current_uid, get_current_gid, get_current_username, get_current_groupname};
|
||||||
use rusqlite::Connection;
|
use rusqlite::Connection;
|
||||||
use log::debug;
|
|
||||||
|
|
||||||
use crate::common::is_binary::is_binary;
|
use crate::common::is_binary::is_binary;
|
||||||
use crate::meta_plugin::MetaPlugin;
|
use crate::meta_plugin::MetaPlugin;
|
||||||
@@ -68,6 +67,26 @@ impl MetaPlugin for BinaryMetaPlugin {
|
|||||||
if remaining_capacity > 0 {
|
if remaining_capacity > 0 {
|
||||||
let bytes_to_copy = std::cmp::min(data.len(), remaining_capacity);
|
let bytes_to_copy = std::cmp::min(data.len(), remaining_capacity);
|
||||||
self.buffer.extend_from_slice(&data[..bytes_to_copy]);
|
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(),
|
Err(_) => "unknown".to_string(),
|
||||||
};
|
};
|
||||||
self.save_meta(conn, item_id, cwd)?;
|
self.save_meta(conn, item_id, cwd)?;
|
||||||
|
// Mark as saved to prevent duplicate saves
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -210,6 +230,7 @@ impl MetaPlugin for UserMetaPlugin {
|
|||||||
None => "unknown".to_string(),
|
None => "unknown".to_string(),
|
||||||
};
|
};
|
||||||
self.save_meta(conn, item_id, user)?;
|
self.save_meta(conn, item_id, user)?;
|
||||||
|
// Mark as saved to prevent duplicate saves
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -251,6 +272,7 @@ impl MetaPlugin for GidMetaPlugin {
|
|||||||
fn initialize(&mut self, conn: &Connection, item_id: i64) -> Result<()> {
|
fn initialize(&mut self, conn: &Connection, item_id: i64) -> Result<()> {
|
||||||
let gid = get_current_gid().to_string();
|
let gid = get_current_gid().to_string();
|
||||||
self.save_meta(conn, item_id, gid)?;
|
self.save_meta(conn, item_id, gid)?;
|
||||||
|
// Mark as saved to prevent duplicate saves
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -298,6 +320,7 @@ impl MetaPlugin for GroupMetaPlugin {
|
|||||||
None => "unknown".to_string(),
|
None => "unknown".to_string(),
|
||||||
};
|
};
|
||||||
self.save_meta(conn, item_id, group)?;
|
self.save_meta(conn, item_id, group)?;
|
||||||
|
// Mark as saved to prevent duplicate saves
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -345,6 +368,7 @@ impl MetaPlugin for ShellMetaPlugin {
|
|||||||
Err(_) => "unknown".to_string(),
|
Err(_) => "unknown".to_string(),
|
||||||
};
|
};
|
||||||
self.save_meta(conn, item_id, shell)?;
|
self.save_meta(conn, item_id, shell)?;
|
||||||
|
// Mark as saved to prevent duplicate saves
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -392,6 +416,7 @@ impl MetaPlugin for ShellPidMetaPlugin {
|
|||||||
Err(_) => process::id().to_string(),
|
Err(_) => process::id().to_string(),
|
||||||
};
|
};
|
||||||
self.save_meta(conn, item_id, pid)?;
|
self.save_meta(conn, item_id, pid)?;
|
||||||
|
// Mark as saved to prevent duplicate saves
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -433,6 +458,7 @@ impl MetaPlugin for KeepPidMetaPlugin {
|
|||||||
fn initialize(&mut self, conn: &Connection, item_id: i64) -> Result<()> {
|
fn initialize(&mut self, conn: &Connection, item_id: i64) -> Result<()> {
|
||||||
let pid = process::id().to_string();
|
let pid = process::id().to_string();
|
||||||
self.save_meta(conn, item_id, pid)?;
|
self.save_meta(conn, item_id, pid)?;
|
||||||
|
// Mark as saved to prevent duplicate saves
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -480,6 +506,7 @@ impl MetaPlugin for HostnameMetaPlugin {
|
|||||||
Err(_) => "unknown".to_string(),
|
Err(_) => "unknown".to_string(),
|
||||||
};
|
};
|
||||||
self.save_meta(conn, item_id, hostname)?;
|
self.save_meta(conn, item_id, hostname)?;
|
||||||
|
// Mark as saved to prevent duplicate saves
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -563,6 +590,7 @@ impl MetaPlugin for FullHostnameMetaPlugin {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
self.save_meta(conn, item_id, hostname)?;
|
self.save_meta(conn, item_id, hostname)?;
|
||||||
|
// Mark as saved to prevent duplicate saves
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user