More step refactoring
This commit is contained in:
29
src/main.rs
29
src/main.rs
@@ -162,10 +162,12 @@ fn run() -> Result<(), Error> {
|
|||||||
println!("Error detecting current distribution: {}", e);
|
println!("Error detecting current distribution: {}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
report.push_result(execute_legacy(
|
execute(
|
||||||
|| linux::run_etc_update(&sudo, run_type),
|
&mut report,
|
||||||
|
"etc-update",
|
||||||
|
|| linux::run_etc_update(sudo.as_ref(), run_type),
|
||||||
config.no_retry(),
|
config.no_retry(),
|
||||||
)?);
|
)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -348,8 +350,18 @@ fn run() -> Result<(), Error> {
|
|||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
{
|
{
|
||||||
report.push_result(execute_legacy(|| linux::flatpak_update(run_type), config.no_retry())?);
|
execute(
|
||||||
report.push_result(execute_legacy(|| linux::run_snap(&sudo, run_type), config.no_retry())?);
|
&mut report,
|
||||||
|
"Flatpak",
|
||||||
|
|| linux::flatpak_update(run_type),
|
||||||
|
config.no_retry(),
|
||||||
|
)?;
|
||||||
|
execute(
|
||||||
|
&mut report,
|
||||||
|
"snap",
|
||||||
|
|| linux::run_snap(sudo.as_ref(), run_type),
|
||||||
|
config.no_retry(),
|
||||||
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(commands) = config.commands() {
|
if let Some(commands) = config.commands() {
|
||||||
@@ -363,7 +375,12 @@ fn run() -> Result<(), Error> {
|
|||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
{
|
{
|
||||||
report.push_result(execute_legacy(|| linux::run_fwupdmgr(run_type), config.no_retry())?);
|
execute(
|
||||||
|
&mut report,
|
||||||
|
"Firmware upgrades",
|
||||||
|
|| linux::run_fwupdmgr(run_type),
|
||||||
|
config.no_retry(),
|
||||||
|
)?;
|
||||||
execute(
|
execute(
|
||||||
&mut report,
|
&mut report,
|
||||||
"Restarts",
|
"Restarts",
|
||||||
|
|||||||
@@ -245,29 +245,20 @@ pub fn run_needrestart(sudo: Option<&PathBuf>, run_type: RunType) -> Result<(),
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn run_fwupdmgr(run_type: RunType) -> Option<(&'static str, bool)> {
|
pub fn run_fwupdmgr(run_type: RunType) -> Result<(), Error> {
|
||||||
if let Some(fwupdmgr) = which("fwupdmgr") {
|
let fwupdmgr = require("fwupdmgr")?;
|
||||||
|
|
||||||
print_separator("Firmware upgrades");
|
print_separator("Firmware upgrades");
|
||||||
|
|
||||||
let success = || -> Result<(), Error> {
|
|
||||||
run_type.execute(&fwupdmgr).arg("refresh").check_run()?;
|
run_type.execute(&fwupdmgr).arg("refresh").check_run()?;
|
||||||
run_type.execute(&fwupdmgr).arg("get-updates").check_run()?;
|
run_type.execute(&fwupdmgr).arg("get-updates").check_run()
|
||||||
Ok(())
|
|
||||||
}()
|
|
||||||
.is_ok();
|
|
||||||
|
|
||||||
return Some(("Firmware upgrade", success));
|
|
||||||
}
|
|
||||||
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn flatpak_update(run_type: RunType) -> Option<(&'static str, bool)> {
|
pub fn flatpak_update(run_type: RunType) -> Result<(), Error> {
|
||||||
if let Some(flatpak) = which("flatpak") {
|
let flatpak = require("flatpak")?;
|
||||||
print_separator("Flatpak User Packages");
|
print_separator("Flatpak User Packages");
|
||||||
|
|
||||||
let success = || -> Result<(), Error> {
|
|
||||||
run_type
|
run_type
|
||||||
.execute(&flatpak)
|
.execute(&flatpak)
|
||||||
.args(&["update", "--user", "-y"])
|
.args(&["update", "--user", "-y"])
|
||||||
@@ -275,58 +266,30 @@ pub fn flatpak_update(run_type: RunType) -> Option<(&'static str, bool)> {
|
|||||||
run_type
|
run_type
|
||||||
.execute(&flatpak)
|
.execute(&flatpak)
|
||||||
.args(&["update", "--system", "-y"])
|
.args(&["update", "--system", "-y"])
|
||||||
.check_run()?;
|
.check_run()
|
||||||
Ok(())
|
|
||||||
}()
|
|
||||||
.is_ok();
|
|
||||||
|
|
||||||
return Some(("Flatpak User Packages", success));
|
|
||||||
}
|
|
||||||
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn run_snap(sudo: &Option<PathBuf>, run_type: RunType) -> Option<(&'static str, bool)> {
|
pub fn run_snap(sudo: Option<&PathBuf>, run_type: RunType) -> Result<(), Error> {
|
||||||
if let Some(sudo) = sudo {
|
let sudo = require_option(sudo)?;
|
||||||
if let Some(snap) = which("snap") {
|
let snap = require("snap")?;
|
||||||
if PathBuf::from("/var/snapd.socket").exists() {
|
|
||||||
|
if !PathBuf::from("/var/snapd.socket").exists() {
|
||||||
|
Err(ErrorKind::SkipStep)?;
|
||||||
|
}
|
||||||
print_separator("snap");
|
print_separator("snap");
|
||||||
|
|
||||||
let success = || -> Result<(), Error> {
|
|
||||||
run_type
|
run_type
|
||||||
.execute(&sudo)
|
.execute(sudo)
|
||||||
.args(&[snap.to_str().unwrap(), "refresh"])
|
.args(&[snap.to_str().unwrap(), "refresh"])
|
||||||
.check_run()?;
|
.check_run()
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}()
|
|
||||||
.is_ok();
|
|
||||||
|
|
||||||
return Some(("snap", success));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn run_etc_update(sudo: &Option<PathBuf>, run_type: RunType) -> Option<(&'static str, bool)> {
|
pub fn run_etc_update(sudo: Option<&PathBuf>, run_type: RunType) -> Result<(), Error> {
|
||||||
if let Some(sudo) = sudo {
|
let sudo = require_option(sudo)?;
|
||||||
if let Some(etc_update) = which("etc-update") {
|
let etc_update = require("etc_update")?;
|
||||||
print_separator("etc-update");
|
print_separator("etc-update");
|
||||||
|
|
||||||
let success = || -> Result<(), Error> {
|
run_type.execute(sudo).arg(&etc_update.to_str().unwrap()).check_run()
|
||||||
run_type.execute(&sudo).arg(&etc_update.to_str().unwrap()).check_run()?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}()
|
|
||||||
.is_ok();
|
|
||||||
|
|
||||||
return Some(("etc-update", success));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user