diff --git a/src/main.rs b/src/main.rs index 998c4fbd..33971643 100644 --- a/src/main.rs +++ b/src/main.rs @@ -149,10 +149,12 @@ fn run() -> Result<(), Error> { if config.should_run(Step::System) { match &distribution { Ok(distribution) => { - report.push_result(execute_legacy( + execute( + &mut report, + "System update", || distribution.upgrade(&sudo, config.cleanup(), run_type), config.no_retry(), - )?); + )?; } Err(e) => { println!("Error detecting current distribution: {}", e); @@ -353,10 +355,12 @@ fn run() -> Result<(), Error> { #[cfg(target_os = "linux")] { report.push_result(execute_legacy(|| linux::run_fwupdmgr(run_type), config.no_retry())?); - report.push_result(execute_legacy( - || linux::run_needrestart(&sudo, run_type), + execute( + &mut report, + "Restarts", + || linux::run_needrestart(sudo.as_ref(), run_type), config.no_retry(), - )?); + )?; } #[cfg(target_os = "macos")] diff --git a/src/steps/os/linux.rs b/src/steps/os/linux.rs index ce308577..51bd4672 100644 --- a/src/steps/os/linux.rs +++ b/src/steps/os/linux.rs @@ -1,7 +1,7 @@ use crate::error::{Error, ErrorKind}; use crate::executor::RunType; use crate::terminal::{print_separator, print_warning}; -use crate::utils::which; +use crate::utils::{require, require_option, which}; use failure::ResultExt; use std::fs; use std::path::PathBuf; @@ -59,10 +59,10 @@ impl Distribution { } #[must_use] - pub fn upgrade(self, sudo: &Option, cleanup: bool, run_type: RunType) -> Option<(&'static str, bool)> { + pub fn upgrade(self, sudo: &Option, cleanup: bool, run_type: RunType) -> Result<(), Error> { print_separator("System update"); - let success = match self { + match self { Distribution::Arch => upgrade_arch_linux(&sudo, cleanup, run_type), Distribution::CentOS => upgrade_redhat(&sudo, run_type), Distribution::Fedora => upgrade_fedora(&sudo, run_type), @@ -70,9 +70,7 @@ impl Distribution { Distribution::Gentoo => upgrade_gentoo(&sudo, run_type), Distribution::OpenSuse => upgrade_opensuse(&sudo, run_type), Distribution::Void => upgrade_void(&sudo, run_type), - }; - - Some(("System update", success.is_ok())) + } } pub fn show_summary(self) { @@ -235,24 +233,15 @@ fn upgrade_debian(sudo: &Option, cleanup: bool, run_type: RunType) -> R Ok(()) } -#[must_use] -pub fn run_needrestart(sudo: &Option, run_type: RunType) -> Option<(&'static str, bool)> { - if let Some(sudo) = sudo { - if let Some(needrestart) = which("needrestart") { - print_separator("Check for needed restarts"); +pub fn run_needrestart(sudo: Option<&PathBuf>, run_type: RunType) -> Result<(), Error> { + let sudo = require_option(sudo)?; + let needrestart = require("needrestart")?; - let success = || -> Result<(), Error> { - run_type.execute(&sudo).arg(needrestart).check_run()?; + print_separator("Check for needed restarts"); - Ok(()) - }() - .is_ok(); + run_type.execute(&sudo).arg(needrestart).check_run()?; - return Some(("Restarts", success)); - } - } - - None + Ok(()) } #[must_use] diff --git a/src/utils.rs b/src/utils.rs index 723d54d2..c8315a9e 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -180,3 +180,11 @@ pub fn require + Debug>(binary_name: T) -> Result(option: Option) -> Result { + if let Some(value) = option { + Ok(value) + } else { + Err(ErrorKind::SkipStep)? + } +}