diff --git a/src/steps/os/linux.rs b/src/steps/os/linux.rs index b4823158..5bfce42a 100644 --- a/src/steps/os/linux.rs +++ b/src/steps/os/linux.rs @@ -1,14 +1,14 @@ use crate::error::{Error, ErrorKind}; use crate::executor::RunType; use crate::terminal::{print_separator, print_warning}; -use crate::utils::{require, require_option, which}; +use crate::utils::{require, require_option, which, PathExt}; use failure::ResultExt; use ini::Ini; use log::debug; use serde::Deserialize; use std::env::var_os; use std::ffi::OsString; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use walkdir::WalkDir; static OS_RELEASE_PATH: &str = "/etc/os-release"; @@ -80,8 +80,7 @@ impl Distribution { match self { Distribution::Arch => upgrade_arch_linux(&sudo, cleanup, run_type, yes), - Distribution::CentOS => upgrade_redhat(&sudo, run_type, yes, false), - Distribution::Fedora => upgrade_redhat(&sudo, run_type, yes, true), + Distribution::CentOS | Distribution::Fedora => upgrade_redhat(&sudo, run_type, yes), Distribution::Debian => upgrade_debian(&sudo, cleanup, run_type, yes), Distribution::Gentoo => upgrade_gentoo(&sudo, run_type), Distribution::Suse => upgrade_suse(&sudo, run_type), @@ -163,10 +162,16 @@ fn upgrade_arch_linux(sudo: &Option, cleanup: bool, run_type: RunType, Ok(()) } -fn upgrade_redhat(sudo: &Option, run_type: RunType, yes: bool, dnf: bool) -> Result<(), Error> { +fn upgrade_redhat(sudo: &Option, run_type: RunType, yes: bool) -> Result<(), Error> { if let Some(sudo) = &sudo { let mut command = run_type.execute(&sudo); - command.args(&[if dnf { "/usr/bin/dnf" } else { "/usr/bin/yum" }, "upgrade"]); + command + .arg( + Path::new("/usr/bin/dnf") + .if_exists() + .unwrap_or_else(|| Path::new("/usr/bin/yum")), + ) + .arg("upgrade"); if yes { command.arg("-y"); } diff --git a/src/utils.rs b/src/utils.rs index 36c8fa3b..ac602bef 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -38,9 +38,12 @@ where fn require(self) -> Result; } -impl PathExt for PathBuf { +impl PathExt for T +where + T: AsRef, +{ fn if_exists(self) -> Option { - if self.exists() { + if self.as_ref().exists() { Some(self) } else { None @@ -48,11 +51,11 @@ impl PathExt for PathBuf { } fn is_descendant_of(&self, ancestor: &Path) -> bool { - self.iter().zip(ancestor.iter()).all(|(a, b)| a == b) + self.as_ref().iter().zip(ancestor.iter()).all(|(a, b)| a == b) } fn require(self) -> Result { - if self.exists() { + if self.as_ref().exists() { Ok(self) } else { Err(ErrorKind::SkipStep.into())