operations: Replace unwrap_or_else with if let Err

i18n
Fries 2 years ago committed by fries1234
parent 2ae9ea34dd
commit 6b90744230

@ -49,19 +49,20 @@ pub async fn clean(options: Options) {
tracing::debug!("Removing orphans: {:?}", orphaned_packages_vec); tracing::debug!("Removing orphans: {:?}", orphaned_packages_vec);
// Remove orphaned packages // Remove orphaned packages
PacmanUninstallBuilder::default() let result = PacmanUninstallBuilder::default()
.no_save(true) .no_save(true)
.recursive(true) .recursive(true)
.no_confirm(noconfirm) .no_confirm(noconfirm)
.packages(orphaned_packages_vec) .packages(orphaned_packages_vec)
.uninstall() .uninstall()
.await .await;
.unwrap_or_else(|_| {
crash!(AppExitCode::PacmanError, "Failed to remove orphans",);
});
if let Err(_) = result {
crash!(AppExitCode::PacmanError, "Failed to remove orphans");
} else {
tracing::info!("Successfully removed orphans"); tracing::info!("Successfully removed orphans");
} }
}
// Prompt the user whether to clear the Amethyst cache // Prompt the user whether to clear the Amethyst cache
let clear_ame_cache = prompt!(default no, "Clear Amethyst's internal PKGBUILD cache?"); let clear_ame_cache = prompt!(default no, "Clear Amethyst's internal PKGBUILD cache?");
@ -89,20 +90,21 @@ pub async fn clean(options: Options) {
// Clear pacman's cache // Clear pacman's cache
// keeps 0 versions of the package in the cache by default // keeps 0 versions of the package in the cache by default
// keeps installed packages in the cache by default // keeps installed packages in the cache by default
PaccacheBuilder::default() let result = PaccacheBuilder::default()
.keep(conf.base.paccache_keep) .keep(conf.base.paccache_keep)
.keep_ins(conf.base.paccache_keep_ins) .keep_ins(conf.base.paccache_keep_ins)
.quiet(quiet) .quiet(quiet)
.remove() .remove()
.await .await;
.unwrap_or_else(|e| {
if let Err(e) = result {
crash!( crash!(
AppExitCode::PacmanError, AppExitCode::PacmanError,
"Failed to clear package cache, {}", "Failed to clear package cache, {}",
e e
) )
}); } else {
tracing::info!("Successfully cleared package cache"); tracing::info!("Successfully cleared package cache");
} }
}
} }

@ -28,11 +28,12 @@ async fn upgrade_repo(options: Options) {
tracing::debug!("Upgrading repo packages"); tracing::debug!("Upgrading repo packages");
PacmanUpgradeBuilder::default() let result = PacmanUpgradeBuilder::default()
.no_confirm(noconfirm) .no_confirm(noconfirm)
.upgrade() .upgrade()
.await .await;
.unwrap_or_else(|_| {
if let Err(_) = result {
let continue_upgrading = prompt!(default no, let continue_upgrading = prompt!(default no,
"Failed to upgrade repo packages, continue to upgrading AUR packages?", "Failed to upgrade repo packages, continue to upgrading AUR packages?",
); );
@ -40,8 +41,9 @@ async fn upgrade_repo(options: Options) {
tracing::info!("Exiting"); tracing::info!("Exiting");
std::process::exit(AppExitCode::PacmanError as i32); std::process::exit(AppExitCode::PacmanError as i32);
} }
}); } else {
tracing::info!("Successfully upgraded repo packages"); tracing::info!("Successfully upgraded repo packages");
}
} }
#[tracing::instrument(level = "trace")] #[tracing::instrument(level = "trace")]

Loading…
Cancel
Save