diff --git a/src/compression_engine/program.rs b/src/compression_engine/program.rs index bcc889d..08107f6 100644 --- a/src/compression_engine/program.rs +++ b/src/compression_engine/program.rs @@ -36,6 +36,24 @@ impl CompressionEngineProgram { } } +fn get_program_path(program: &str) -> Result { + debug!("COMPRESSION: Looking for executable: {}", program); + if let Ok(path) = env::var("PATH") { + for p in path.split(':') { + let p_str = format!("{}/{}", p, program); + let stat = fs::metadata(p_str.clone()); + if let Ok(stat) = stat { + let md = stat; + let permissions = md.permissions(); + if md.is_file() && permissions.mode() & 0o111 != 0 { + return Ok(p_str); + } + } + } + } + Err(anyhow!("Unable to find binary {} in PATH", program)) +} + impl CompressionEngine for CompressionEngineProgram { fn is_supported(&self) -> bool { self.supported diff --git a/src/main.rs b/src/main.rs index 94ddd0e..d8ae213 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,13 +9,10 @@ extern crate directories; use directories::ProjectDirs; extern crate prettytable; -use prettytable::format; use prettytable::format::consts::FORMAT_NO_BORDER_LINE_SEPARATOR; -use prettytable::format::{Alignment, TableFormat}; use std::str::FromStr; -#[macro_use] extern crate lazy_static; pub mod compression_engine; diff --git a/src/modes/status.rs b/src/modes/status.rs index eabfa0e..7c0f9d9 100644 --- a/src/modes/status.rs +++ b/src/modes/status.rs @@ -8,8 +8,9 @@ use crate::compression_engine::COMPRESSION_PROGRAMS; use crate::compression_engine::CompressionType; use crate::compression_engine::program::CompressionEngineProgram; -use crate::FORMAT_BOX_CHARS_NO_BORDER_LINE_SEPARATOR; -use crate::FORMAT_NO_BORDER_LINE_SEPARATOR; +use prettytable::format::TableFormat; +use crate::modes::common::get_format_box_chars_no_border_line_separator; +use prettytable::format::consts::FORMAT_NO_BORDER_LINE_SEPARATOR; use prettytable::color; use prettytable::row; use prettytable::{Attr, Cell, Row, Table}; @@ -21,7 +22,7 @@ fn build_path_table(data_path: PathBuf, db_path: PathBuf) -> Table { let mut path_table = Table::new(); if std::io::stdout().is_terminal() { - path_table.set_format(*FORMAT_BOX_CHARS_NO_BORDER_LINE_SEPARATOR); + path_table.set_format(get_format_box_chars_no_border_line_separator()); } else { path_table.set_format(*FORMAT_NO_BORDER_LINE_SEPARATOR); } @@ -57,7 +58,7 @@ fn build_path_table(data_path: PathBuf, db_path: PathBuf) -> Table { fn build_compression_table() -> Table { let mut compression_table = Table::new(); if std::io::stdout().is_terminal() { - compression_table.set_format(*FORMAT_BOX_CHARS_NO_BORDER_LINE_SEPARATOR); + compression_table.set_format(get_format_box_chars_no_border_line_separator()); } else { compression_table.set_format(*FORMAT_NO_BORDER_LINE_SEPARATOR); } @@ -114,7 +115,7 @@ fn build_compression_table() -> Table { fn build_meta_plugin_table(enabled_meta_plugins: &Vec) -> Table { let mut meta_plugin_table = Table::new(); if std::io::stdout().is_terminal() { - meta_plugin_table.set_format(*FORMAT_BOX_CHARS_NO_BORDER_LINE_SEPARATOR); + meta_plugin_table.set_format(get_format_box_chars_no_border_line_separator()); } else { meta_plugin_table.set_format(*FORMAT_NO_BORDER_LINE_SEPARATOR); } diff --git a/src/tests.rs b/src/tests.rs index 6cc0685..ce48346 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -17,7 +17,7 @@ mod tests { cmd.args(args) .env("KEEP_DIR", keep_dir); - if let Some(data) = stdin_data { + if let Some(_data) = stdin_data { cmd.stdin(std::process::Stdio::piped()); }