From 3186fef105b59d49b3abc813c168a05239982fc5 Mon Sep 17 00:00:00 2001 From: Hsiao-nan Cheung Date: Wed, 20 Mar 2024 17:17:48 +0800 Subject: [PATCH] fix(update/uninstall): Remove items from PATH correctly (#5833) --- CHANGELOG.md | 1 + lib/install.ps1 | 15 ++++++++++----- libexec/scoop-update.ps1 | 5 ++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b33caca7ec..c29b636dda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ - **core:** Do not call `scoop` externally from inside the code ([#5695](https://github.com/ScoopInstaller/Scoop/issues/5695)) - **scoop-checkup:** Don't throw 7zip error when external 7zip is used ([#5703](https://github.com/ScoopInstaller/Scoop/issues/5703)) - **config:** Warn users about misconfigured GitHub token ([#5777](https://github.com/ScoopInstaller/Scoop/issues/5777)) +- **update/uninstall:** Remove items from PATH correctly ([#5833](https://github.com/ScoopInstaller/Scoop/issues/5833)) ### Performance Improvements diff --git a/lib/install.ps1 b/lib/install.ps1 index 3fe945229a..0ed13707e8 100644 --- a/lib/install.ps1 +++ b/lib/install.ps1 @@ -917,7 +917,6 @@ function env_add_path($manifest, $dir, $global, $arch) { } else { $path_dir = Join-Path $dir $_ } - if (!(is_in_dir $dir $path_dir)) { abort "Error in manifest: env_add_path '$_' is outside the app directory." } @@ -928,10 +927,16 @@ function env_add_path($manifest, $dir, $global, $arch) { function env_rm_path($manifest, $dir, $global, $arch) { $env_add_path = arch_specific 'env_add_path' $manifest $arch - $env_add_path | Where-Object { $_ } | ForEach-Object { - $path_dir = Join-Path $dir $_ - - remove_from_path $path_dir $global + $dir = $dir.TrimEnd('\') + if ($env_add_path) { + $env_add_path | Where-Object { $_ } | ForEach-Object { + if ($_ -eq '.') { + $path_dir = $dir + } else { + $path_dir = Join-Path $dir $_ + } + remove_from_path $path_dir $global + } } } diff --git a/libexec/scoop-update.ps1 b/libexec/scoop-update.ps1 index 50f82090a5..e632be72fb 100644 --- a/libexec/scoop-update.ps1 +++ b/libexec/scoop-update.ps1 @@ -289,15 +289,14 @@ function update($app, $global, $quiet = $false, $independent, $suggested, $use_c Write-Host "Uninstalling '$app' ($old_version)" run_uninstaller $old_manifest $architecture $dir rm_shims $app $old_manifest $global $architecture - env_rm_path $old_manifest $dir $global $architecture - env_rm $old_manifest $global $architecture # If a junction was used during install, that will have been used # as the reference directory. Otherwise it will just be the version # directory. $refdir = unlink_current $dir - uninstall_psmodule $old_manifest $refdir $global + env_rm_path $old_manifest $refdir $global $architecture + env_rm $old_manifest $global $architecture if ($force -and ($old_version -eq $version)) { if (!(Test-Path "$dir/../_$version.old")) {