fix: remove item_id parameter from MetaPlugin methods and update implementations
Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
@@ -110,7 +110,7 @@ pub enum MetaPluginType {
|
|||||||
WordCount,
|
WordCount,
|
||||||
Cwd,
|
Cwd,
|
||||||
Binary,
|
Binary,
|
||||||
User, // Consolidated Uid, User, Gid, Group into User
|
User,
|
||||||
Shell,
|
Shell,
|
||||||
ShellPid,
|
ShellPid,
|
||||||
KeepPid,
|
KeepPid,
|
||||||
@@ -254,10 +254,7 @@ pub fn get_meta_plugin(meta_plugin_type: MetaPluginType) -> Box<dyn MetaPlugin>
|
|||||||
MetaPluginType::WordCount => Box::new(MetaPluginProgram::new_simple("wc", vec!["-w"], "word_count".to_string(), true)),
|
MetaPluginType::WordCount => Box::new(MetaPluginProgram::new_simple("wc", vec!["-w"], "word_count".to_string(), true)),
|
||||||
MetaPluginType::Cwd => Box::new(CwdMetaPlugin::new_simple()),
|
MetaPluginType::Cwd => Box::new(CwdMetaPlugin::new_simple()),
|
||||||
MetaPluginType::Binary => Box::new(BinaryMetaPlugin::new_simple()),
|
MetaPluginType::Binary => Box::new(BinaryMetaPlugin::new_simple()),
|
||||||
MetaPluginType::Uid => Box::new(UserMetaPlugin::new_simple()), // Consolidated into UserMetaPlugin
|
|
||||||
MetaPluginType::User => Box::new(UserMetaPlugin::new_simple()),
|
MetaPluginType::User => Box::new(UserMetaPlugin::new_simple()),
|
||||||
MetaPluginType::Gid => Box::new(UserMetaPlugin::new_simple()), // Consolidated into UserMetaPlugin
|
|
||||||
MetaPluginType::Group => Box::new(UserMetaPlugin::new_simple()), // Consolidated into UserMetaPlugin
|
|
||||||
MetaPluginType::Shell => Box::new(ShellMetaPlugin::new_simple()),
|
MetaPluginType::Shell => Box::new(ShellMetaPlugin::new_simple()),
|
||||||
MetaPluginType::ShellPid => Box::new(ShellPidMetaPlugin::new_simple()),
|
MetaPluginType::ShellPid => Box::new(ShellPidMetaPlugin::new_simple()),
|
||||||
MetaPluginType::KeepPid => Box::new(KeepPidMetaPlugin::new_simple()),
|
MetaPluginType::KeepPid => Box::new(KeepPidMetaPlugin::new_simple()),
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ impl MagicFileMetaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Helper function to process all magic types and collect metadata
|
/// Helper function to process all magic types and collect metadata
|
||||||
fn process_magic_types(&self, item_id: i64) -> Vec<crate::meta_plugin::MetaData> {
|
fn process_magic_types(&self) -> Vec<crate::meta_plugin::MetaData> {
|
||||||
let mut metadata = Vec::new();
|
let mut metadata = Vec::new();
|
||||||
|
|
||||||
// Define the types to process with their corresponding flags
|
// Define the types to process with their corresponding flags
|
||||||
@@ -103,7 +103,7 @@ impl MagicFileMetaPlugin {
|
|||||||
("file_type", CookieFlags::default()),
|
("file_type", CookieFlags::default()),
|
||||||
];
|
];
|
||||||
|
|
||||||
for (name, flags) in types_to_process {
|
for (name, flags) & types_to_process {
|
||||||
if let Ok(result) = self.get_magic_result(flags) {
|
if let Ok(result) = self.get_magic_result(flags) {
|
||||||
if !result.is_empty() {
|
if !result.is_empty() {
|
||||||
// Use process_metadata_outputs to handle output mapping
|
// Use process_metadata_outputs to handle output mapping
|
||||||
@@ -124,9 +124,7 @@ impl MagicFileMetaPlugin {
|
|||||||
|
|
||||||
impl MetaPlugin for MagicFileMetaPlugin {
|
impl MetaPlugin for MagicFileMetaPlugin {
|
||||||
|
|
||||||
fn initialize(&mut self, item_id: i64) -> crate::meta_plugin::MetaPluginResponse {
|
fn initialize(&mut self) -> crate::meta_plugin::MetaPluginResponse {
|
||||||
self.item_id = Some(item_id);
|
|
||||||
|
|
||||||
// Initialize the magic cookie once
|
// Initialize the magic cookie once
|
||||||
let cookie = match Cookie::open(Default::default()) {
|
let cookie = match Cookie::open(Default::default()) {
|
||||||
Ok(cookie) => cookie,
|
Ok(cookie) => cookie,
|
||||||
@@ -152,11 +150,7 @@ impl MetaPlugin for MagicFileMetaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn finalize(&mut self) -> crate::meta_plugin::MetaPluginResponse {
|
fn finalize(&mut self) -> crate::meta_plugin::MetaPluginResponse {
|
||||||
let metadata = if let Some(item_id) = self.item_id {
|
let metadata = self.process_magic_types();
|
||||||
self.process_magic_types(item_id)
|
|
||||||
} else {
|
|
||||||
Vec::new()
|
|
||||||
};
|
|
||||||
|
|
||||||
crate::meta_plugin::MetaPluginResponse {
|
crate::meta_plugin::MetaPluginResponse {
|
||||||
metadata,
|
metadata,
|
||||||
@@ -175,9 +169,7 @@ impl MetaPlugin for MagicFileMetaPlugin {
|
|||||||
|
|
||||||
// Check if we've reached our buffer limit and return metadata
|
// Check if we've reached our buffer limit and return metadata
|
||||||
if self.buffer.len() >= self.max_buffer_size {
|
if self.buffer.len() >= self.max_buffer_size {
|
||||||
if let Some(item_id) = self.item_id {
|
metadata = self.process_magic_types();
|
||||||
metadata = self.process_magic_types(item_id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,8 @@ use log::*;
|
|||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::process::{Command, Stdio, Child};
|
use std::process::{Command, Stdio, Child};
|
||||||
use which::which;
|
use which::which;
|
||||||
use rusqlite::Connection;
|
|
||||||
|
|
||||||
use crate::meta_plugin::MetaPlugin;
|
use crate::meta_plugin::{MetaPlugin, MetaData};
|
||||||
|
|
||||||
pub struct MetaPluginProgram {
|
pub struct MetaPluginProgram {
|
||||||
pub program: String,
|
pub program: String,
|
||||||
@@ -164,7 +163,7 @@ impl MetaPlugin for MetaPluginProgram {
|
|||||||
self.result = Some(result);
|
self.result = Some(result);
|
||||||
|
|
||||||
// Create metadata to be returned
|
// Create metadata to be returned
|
||||||
metadata.push(MetaData {
|
metadata.push(crate::meta_plugin::MetaData {
|
||||||
name: self.meta_name.clone(),
|
name: self.meta_name.clone(),
|
||||||
value: result,
|
value: result,
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user