refactor: remove is_default from meta plugins and add read_time/read_rate plugins

Co-authored-by: aider (openai/andrew.openrouter.qwen.qwen3-coder) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-07-29 11:32:48 -03:00
parent ee6869a94c
commit d530f1bc43
3 changed files with 15 additions and 18 deletions

View File

@@ -21,6 +21,8 @@ pub enum MetaPluginType {
FileMagic, FileMagic,
DigestSha256, DigestSha256,
DigestMd5, DigestMd5,
ReadTime,
ReadRate,
} }
pub trait MetaPlugin { pub trait MetaPlugin {
@@ -34,10 +36,6 @@ pub trait MetaPlugin {
fn update(&mut self, data: &[u8]); fn update(&mut self, data: &[u8]);
fn meta_name(&mut self) -> String; fn meta_name(&mut self) -> String;
fn is_default(&self) -> bool {
false
}
} }
use std::io::Write; use std::io::Write;
@@ -48,9 +46,12 @@ lazy_static! {
let program = MetaPluginProgram::new("file", vec!["-bE", "-"], "file_magic".to_string(), true); let program = MetaPluginProgram::new("file", vec!["-bE", "-"], "file_magic".to_string(), true);
if program.supported { Some(program) } else { None } if program.supported { Some(program) } else { None }
} }
MetaPluginType::DigestSha256 => None, MetaPluginType::DigestSha256 => {
let program = MetaPluginProgram::new("sha256sum", vec![], "digest_sha256".to_string(), true);
if program.supported { Some(program) } else { None }
}
MetaPluginType::DigestMd5 => { MetaPluginType::DigestMd5 => {
let program = MetaPluginProgram::new("md5sum", vec![], "digest_md5".to_string(), false); let program = MetaPluginProgram::new("md5sum", vec![], "digest_md5".to_string(), true);
if program.supported { Some(program) } else { None } if program.supported { Some(program) } else { None }
} }
}; };
@@ -60,7 +61,9 @@ pub fn get_meta_plugin(meta_plugin_type: MetaPluginType) -> Box<dyn MetaPlugin>
match meta_plugin_type { match meta_plugin_type {
MetaPluginType::FileMagic => Box::new(MetaPluginProgram::new("file", vec!["-bE", "-"], "file_magic".to_string(), true)), MetaPluginType::FileMagic => Box::new(MetaPluginProgram::new("file", vec!["-bE", "-"], "file_magic".to_string(), true)),
MetaPluginType::DigestSha256 => Box::new(DigestSha256MetaPlugin::new()), MetaPluginType::DigestSha256 => Box::new(DigestSha256MetaPlugin::new()),
MetaPluginType::DigestMd5 => Box::new(MetaPluginProgram::new("md5sum", vec![], "digest_md5".to_string(), false)), MetaPluginType::DigestMd5 => Box::new(MetaPluginProgram::new("md5sum", vec![], "digest_md5".to_string(), true)),
MetaPluginType::ReadTime => Box::new(ReadTimeMetaPlugin::new()),
MetaPluginType::ReadRate => Box::new(ReadRateMetaPlugin::new()),
} }
} }

View File

@@ -40,9 +40,6 @@ impl MetaPlugin for DigestSha256MetaPlugin {
self.meta_name.clone() self.meta_name.clone()
} }
fn is_default(&self) -> bool {
true
}
} }
// Dummy writer that implements Write but doesn't do anything // Dummy writer that implements Write but doesn't do anything

View File

@@ -16,12 +16,12 @@ pub struct MetaPluginProgram {
pub args: Vec<String>, pub args: Vec<String>,
pub supported: bool, pub supported: bool,
pub meta_name: String, pub meta_name: String,
pub is_default: bool, pub split_whitespace: bool,
buffer: Vec<u8>, buffer: Vec<u8>,
} }
impl MetaPluginProgram { impl MetaPluginProgram {
pub fn new(program: &str, args: Vec<&str>, meta_name: String, is_default: bool) -> MetaPluginProgram { pub fn new(program: &str, args: Vec<&str>, meta_name: String, split_whitespace: bool) -> MetaPluginProgram {
let program_path = get_program_path(program); let program_path = get_program_path(program);
let supported = program_path.is_ok(); let supported = program_path.is_ok();
@@ -30,7 +30,7 @@ impl MetaPluginProgram {
args: args.iter().map(|s| s.to_string()).collect(), args: args.iter().map(|s| s.to_string()).collect(),
supported, supported,
meta_name, meta_name,
is_default, split_whitespace,
buffer: Vec::new(), buffer: Vec::new(),
} }
} }
@@ -90,8 +90,8 @@ impl MetaPlugin for MetaPluginProgram {
let stdout = String::from_utf8_lossy(&output.stdout); let stdout = String::from_utf8_lossy(&output.stdout);
let trimmed_result = stdout.trim(); let trimmed_result = stdout.trim();
// For certain programs like md5sum, we only want the first part before whitespace // For certain programs, we only want the first part before whitespace
if self.program.ends_with("sum") { if self.split_whitespace {
let parts: Vec<&str> = trimmed_result.split_whitespace().collect(); let parts: Vec<&str> = trimmed_result.split_whitespace().collect();
if !parts.is_empty() { if !parts.is_empty() {
Ok(parts[0].to_string()) Ok(parts[0].to_string())
@@ -118,9 +118,6 @@ impl MetaPlugin for MetaPluginProgram {
self.meta_name.clone() self.meta_name.clone()
} }
fn is_default(&self) -> bool {
self.is_default
}
} }
fn get_program_path(program: &str) -> Result<String> { fn get_program_path(program: &str) -> Result<String> {