From 7386eeddc7c414eed2af91667f3c9cdeb9352948 Mon Sep 17 00:00:00 2001 From: Hsiao-nan Cheung Date: Wed, 9 Feb 2022 18:27:37 +0800 Subject: [PATCH] fix(scoop-update): Enforce $null array (#4725) --- CHANGELOG.md | 1 + lib/install.ps1 | 2 +- libexec/scoop-update.ps1 | 12 +++++++----- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b3a3c40e8..cc7e85055e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ - **shim:** Fix `sh` shim error in WSL ([#4637](https://github.com/ScoopInstaller/Scoop/issues/4637)) - **versions:** Fix wrong version number when only one version dir ([#4679](https://github.com/ScoopInstaller/Scoop/issues/4679)) - **versions:** Get current version from failed installation if possible ([#4720](https://github.com/ScoopInstaller/Scoop/issues/4720)) + - **scoop-update:** Enforce $null array ([#4725](https://github.com/ScoopInstaller/Scoop/issues/4725)) - **scoop-cleanup:** Remove apps other than current version ([#4665](https://github.com/ScoopInstaller/Scoop/issues/4665)) - **scoop-update:** Skip updating non git buckets ([#4670](https://github.com/ScoopInstaller/Scoop/issues/4670)) - **scoop-update:** Remove 'Done.' output ([#4672](https://github.com/ScoopInstaller/Scoop/issues/4672)) diff --git a/lib/install.ps1 b/lib/install.ps1 index b56f5a0af1..135bdc14cf 100644 --- a/lib/install.ps1 +++ b/lib/install.ps1 @@ -1075,7 +1075,7 @@ function ensure_none_failed($apps) { foreach ($global in $true, $false) { if (failed $app $global) { if (installed $app $global) { - warn "Repair previous failed installation of $app." + info "Repair previous failed installation of $app." & "$PSScriptRoot\..\libexec\scoop-reset.ps1" $app$(if ($global) { ' --global' }) } else { warn "Purging previous failed installation of $app." diff --git a/libexec/scoop-update.ps1 b/libexec/scoop-update.ps1 index d4653ab028..85cd37365c 100644 --- a/libexec/scoop-update.ps1 +++ b/libexec/scoop-update.ps1 @@ -274,18 +274,20 @@ function update($app, $global, $quiet = $false, $independent, $suggested, $use_c install_app $app $architecture $global $suggested $use_cache $check_hash } else { # Also add missing dependencies - $apps = (Get-Dependency $app $architecture) -ne $app + $apps = @(Get-Dependency $app $architecture) -ne $app ensure_none_failed $apps - @($apps) + $app | Where-Object { !(installed $_) } | ForEach-Object { install_app $_ $architecture $global $suggested $use_cache $check_hash } + $apps.Where({ !(installed $_) }) + $app | ForEach-Object { install_app $_ $architecture $global $suggested $use_cache $check_hash } } } if (-not ($apps -or $all)) { if ($global) { - "scoop update: --global is invalid when is not specified."; exit 1 + error 'scoop update: --global is invalid when is not specified.' + exit 1 } if (!$use_cache) { - "scoop update: --no-cache is invalid when is not specified."; exit 1 + error 'scoop update: --no-cache is invalid when is not specified.' + exit 1 } update_scoop } else { @@ -320,7 +322,7 @@ if (-not ($apps -or $all)) { } } elseif ($apps_param -ne '*') { if ($status.installed) { - ensure_none_failed $app $global + ensure_none_failed $app Write-Host "$app`: $($status.version) (latest version)" -ForegroundColor Green } else { info 'Please reinstall it or fix the manifest.'