Convert more legacy steps
This commit is contained in:
14
src/main.rs
14
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")]
|
||||
|
||||
@@ -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<PathBuf>, cleanup: bool, run_type: RunType) -> Option<(&'static str, bool)> {
|
||||
pub fn upgrade(self, sudo: &Option<PathBuf>, 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<PathBuf>, cleanup: bool, run_type: RunType) -> R
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn run_needrestart(sudo: &Option<PathBuf>, run_type: RunType) -> Option<(&'static str, bool)> {
|
||||
if let Some(sudo) = sudo {
|
||||
if let Some(needrestart) = which("needrestart") {
|
||||
pub fn run_needrestart(sudo: Option<&PathBuf>, run_type: RunType) -> Result<(), Error> {
|
||||
let sudo = require_option(sudo)?;
|
||||
let needrestart = require("needrestart")?;
|
||||
|
||||
print_separator("Check for needed restarts");
|
||||
|
||||
let success = || -> Result<(), Error> {
|
||||
run_type.execute(&sudo).arg(needrestart).check_run()?;
|
||||
|
||||
Ok(())
|
||||
}()
|
||||
.is_ok();
|
||||
|
||||
return Some(("Restarts", success));
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
|
||||
@@ -180,3 +180,11 @@ pub fn require<T: AsRef<OsStr> + Debug>(binary_name: T) -> Result<PathBuf, Error
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn require_option<T>(option: Option<T>) -> Result<T, Error> {
|
||||
if let Some(value) = option {
|
||||
Ok(value)
|
||||
} else {
|
||||
Err(ErrorKind::SkipStep)?
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user