refactor: remove magic function and related code

This commit is contained in:
Andrew Phillips (aider)
2025-05-22 13:57:00 -03:00
parent f2d210c4d1
commit a68d75351f
2 changed files with 0 additions and 54 deletions

View File

@@ -54,41 +54,6 @@ pub trait CompressionEngine {
self.copy(file_path, &mut stdout)
}
fn magic(&self, file_path: PathBuf) -> Result<String> {
let mut buffer = [0; libc::BUFSIZ as usize];
let mut reader = self.open(file_path)?;
let buffer_size = reader.read(&mut buffer[..])?;
//let cookie = magic::Cookie::open(magic::cookie::Flags::ERROR)?;
// load the system's default database
//let database = Default::default();
//let cookie = cookie.load(&database).map_err(|error| { anyhow!(error.to_string())})?;
//let magic = cookie.buffer(&buffer[0..n])?;
let program = "file";
let args = ["-bE", "-"];
let process = Command::new(program)
.args(args)
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn()
.context(anyhow!(
"Unable to spawn child process: {:?} {:?}",
program,
args
))?;
let mut stdin = process.stdin.unwrap();
stdin.write_all(&buffer[0..buffer_size])?;
drop(stdin);
let mut magic = String::new();
process.stdout.unwrap().read_to_string(&mut magic)?;
Ok(magic)
}
fn size(&self, file_path: PathBuf) -> Result<usize> {
let mut reader = self.open(file_path)?;
let mut buffer = [0; libc::BUFSIZ as usize];

View File

@@ -120,25 +120,6 @@ fn show_item(
file_size_cell,
]));
// Corrected logic for file_magic_cell:
// compression_type_val is already the successfully parsed CompressionType.
// The .expect() here will panic if get_compression_engine returns an Err.
let compression_engine = get_compression_engine(compression_type_val.clone())
.expect("Unable to get compression engine");
let magic_result = compression_engine.magic(item_path_buf.clone()); // Use cloned item_path_buf
let file_magic_cell = match magic_result {
Ok(magic_str) => Cell::new(magic_str.as_str()),
Err(e) => Cell::new(&e.to_string())
.with_style(Attr::ForegroundColor(prettytable::color::RED))
.with_style(Attr::Bold),
};
table.add_row(Row::new(vec![
Cell::new("File Magic").with_style(Attr::Bold),
file_magic_cell,
]));
table.add_row(Row::new(vec![
Cell::new("Tags").with_style(Attr::Bold),
Cell::new(&item_tags.join(" ")),