From 8e97c2bcc695e93f83bef149c45cbabae5986259 Mon Sep 17 00:00:00 2001 From: Richard Kuhnt Date: Mon, 3 Apr 2017 13:13:02 +0200 Subject: [PATCH] Allow uninstalling multiple programs even if some fail or don't exist --- lib/core.ps1 | 3 ++- libexec/scoop-uninstall.ps1 | 32 +++++++++++++++++++++++--------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/lib/core.ps1 b/lib/core.ps1 index 70e082a0..29c8cfd7 100644 --- a/lib/core.ps1 +++ b/lib/core.ps1 @@ -33,7 +33,8 @@ function is_admin { # messages function abort($msg) { write-host $msg -f darkred; exit 1 } -function warn($msg) { write-host $msg -f darkyellow; } +function error($msg) { write-host $msg -f darkred } +function warn($msg) { write-host $msg -f darkyellow } function success($msg) { write-host $msg -f darkgreen } function filesize($length) { diff --git a/libexec/scoop-uninstall.ps1 b/libexec/scoop-uninstall.ps1 index 50a2c820..cc0e56a9 100644 --- a/libexec/scoop-uninstall.ps1 +++ b/libexec/scoop-uninstall.ps1 @@ -39,7 +39,8 @@ foreach($app in $apps) { "Try uninstalling $(if($global) { 'without' } else { 'with' }) the --global (or -g) flag instead." exit 1 } else { - abort "'$app' isn't installed." + error "'$app' isn't installed." + continue } } } @@ -57,7 +58,8 @@ foreach($app in $apps) { try { test-path $dir -ea stop | out-null } catch [unauthorizedaccessexception] { - abort "Access denied: $dir. You might need to restart." + error "Access denied: $dir. You might need to restart." + continue } $manifest = installed_manifest $app $version $global @@ -78,16 +80,24 @@ foreach($app in $apps) { env_rm_path $manifest $refdir $global env_rm $manifest $global - try { rm -r $dir -ea stop -force } - catch { abort "Couldn't remove '$(friendly_path $dir)'; it may be in use." } + try { + rm -r $dir -ea stop -force + } catch { + error "Couldn't remove '$(friendly_path $dir)'; it may be in use." + continue + } # remove older versions $old = @(versions $app $global) foreach($oldver in $old) { - "Removing older version ($oldver)." + write-host "Removing older version ($oldver)." $dir = versiondir $app $oldver $global - try { rm -r -force -ea stop $dir } - catch { abort "Couldn't remove '$(friendly_path $dir)'; it may be in use." } + try { + rm -r -force -ea stop $dir + } catch { + error "Couldn't remove '$(friendly_path $dir)'; it may be in use." + continue + } } if(@(versions $app).length -eq 0) { @@ -106,8 +116,12 @@ foreach($app in $apps) { $persist_dir = persistdir $app $global if (Test-Path $persist_dir) { - try { rm -r $persist_dir -ea stop -force } - catch { abort "Couldn't remove '$(friendly_path $persist_dir)'; it may be in use." } + try { + rm -r $persist_dir -ea stop -force + } catch { + error "Couldn't remove '$(friendly_path $persist_dir)'; it may be in use." + continue + } } }