diff --git a/crates/pacdef_core/src/core.rs b/crates/pacdef_core/src/core.rs index a71243c..a2d002d 100644 --- a/crates/pacdef_core/src/core.rs +++ b/crates/pacdef_core/src/core.rs @@ -12,7 +12,7 @@ use crate::args; use crate::backend::{Backend, Backends, ToDoPerBackend}; use crate::cmd::run_edit_command; use crate::env::get_single_var; -use crate::path::get_group_dir; +use crate::path::{binary_in_path, get_group_dir}; use crate::review; use crate::search; use crate::ui::get_user_confirmation; @@ -72,7 +72,7 @@ impl Pacdef { Some(("package", args)) => match args.subcommand() { Some((CLEAN, _)) => self.clean_packages(), - Some((REVIEW, _)) => review::review(self.get_unmanaged_packages(), self.groups) + Some((REVIEW, _)) => review::review(self.get_unmanaged_packages()?, self.groups) .context("review unmanaged packages"), Some((SEARCH, args)) => { search::search_packages(args, &self.groups).context("searching packages") @@ -91,7 +91,7 @@ impl Pacdef { } } - fn get_missing_packages(&mut self) -> ToDoPerBackend { + fn get_missing_packages(&mut self) -> Result { let mut to_install = ToDoPerBackend::new(); for mut backend in Backends::iter() { @@ -103,6 +103,10 @@ impl Pacdef { continue; } + if !binary_in_path(backend.get_binary())? { + continue; + } + self.overwrite_values_from_config(&mut *backend); backend.load(&self.groups); @@ -112,7 +116,7 @@ impl Pacdef { }; } - to_install + Ok(to_install) } #[allow(clippy::unused_self, unused_variables)] @@ -127,7 +131,7 @@ impl Pacdef { } fn install_packages(&mut self) -> Result<()> { - let to_install = self.get_missing_packages(); + let to_install = self.get_missing_packages()?; if to_install.nothing_to_do_for_all_backends() { println!("nothing to do"); @@ -163,7 +167,7 @@ impl Pacdef { } fn show_unmanaged_packages(mut self) -> Result<()> { - let unmanaged_per_backend = &self.get_unmanaged_packages(); + let unmanaged_per_backend = &self.get_unmanaged_packages()?; if unmanaged_per_backend.nothing_to_do_for_all_backends() { return Ok(()); @@ -174,7 +178,7 @@ impl Pacdef { .context("printing things to do") } - fn get_unmanaged_packages(&mut self) -> ToDoPerBackend { + fn get_unmanaged_packages(&mut self) -> Result { let mut result = ToDoPerBackend::new(); for mut backend in Backends::iter() { @@ -186,6 +190,10 @@ impl Pacdef { continue; } + if !binary_in_path(backend.get_binary())? { + continue; + } + self.overwrite_values_from_config(&mut *backend); backend.load(&self.groups); @@ -194,7 +202,7 @@ impl Pacdef { Err(error) => show_error(&error, &*backend), }; } - result + Ok(result) } fn show_groups(self) { @@ -206,7 +214,7 @@ impl Pacdef { } fn clean_packages(mut self) -> Result<()> { - let to_remove = self.get_unmanaged_packages(); + let to_remove = self.get_unmanaged_packages()?; if to_remove.nothing_to_do_for_all_backends() { println!("nothing to do"); diff --git a/crates/pacdef_core/src/path.rs b/crates/pacdef_core/src/path.rs index a3ffdf2..9132842 100644 --- a/crates/pacdef_core/src/path.rs +++ b/crates/pacdef_core/src/path.rs @@ -65,3 +65,14 @@ pub fn get_config_path_old_version() -> Result { file.push(CONFIG_FILE_NAME_OLD); Ok(file) } + +pub(crate) fn binary_in_path(name: &str) -> Result { + let paths = env::var_os("PATH").context("getting $PATH")?; + for dir in env::split_paths(&paths) { + let full_path = dir.join(name); + if full_path.is_file() { + return Ok(true); + } + } + Ok(false) +}