From a68d75351fe3ec29dd1f8a8bde218a9e8a6a652c Mon Sep 17 00:00:00 2001 From: "Andrew Phillips (aider)" Date: Thu, 22 May 2025 13:57:00 -0300 Subject: [PATCH] refactor: remove magic function and related code --- src/compression_engine.rs | 35 ----------------------------------- src/modes/info.rs | 19 ------------------- 2 files changed, 54 deletions(-) diff --git a/src/compression_engine.rs b/src/compression_engine.rs index 98aa84b..f7d6dce 100755 --- a/src/compression_engine.rs +++ b/src/compression_engine.rs @@ -54,41 +54,6 @@ pub trait CompressionEngine { self.copy(file_path, &mut stdout) } - fn magic(&self, file_path: PathBuf) -> Result { - 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 { let mut reader = self.open(file_path)?; let mut buffer = [0; libc::BUFSIZ as usize]; diff --git a/src/modes/info.rs b/src/modes/info.rs index 22233cc..5df29b9 100644 --- a/src/modes/info.rs +++ b/src/modes/info.rs @@ -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(" ")),