diff --git a/CHANGELOG.md b/CHANGELOG.md index 82619d0612..44b7aa9fda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ - **scoop:** Pass CLI arguments as string objects ([#4931](https://github.com/ScoopInstaller/Scoop/issues/4931)) - **scoop-info:** Fix error message when manifest is not found ([#4935](https://github.com/ScoopInstaller/Scoop/issues/4935)) - **scoop-search:** Require files in 'bucket' dir for remote known buckets ([#4943](https://github.com/ScoopInstaller/Scoop/issues/4943)) +- **update:** Prevent uninstall when update ([#4949](https://github.com/ScoopInstaller/Scoop/issues/4949)) ### Documentation diff --git a/libexec/scoop-update.ps1 b/libexec/scoop-update.ps1 index 17933df278..d06bc5d669 100644 --- a/libexec/scoop-update.ps1 +++ b/libexec/scoop-update.ps1 @@ -66,20 +66,31 @@ function update_scoop() { $show_update_log = get_config 'show_update_log' $true $currentdir = fullpath $(versiondir 'scoop' 'current') if (!(Test-Path "$currentdir\.git")) { - $newdir = fullpath $(versiondir 'scoop' 'new') + $newdir = "$currentdir\..\new" + $olddir = "$currentdir\..\old" # get git scoop git_cmd clone -q $configRepo --branch $configBranch --single-branch "`"$newdir`"" # check if scoop was successful downloaded - if (!(Test-Path "$newdir")) { - abort 'Scoop update failed.' + if (!(Test-Path "$newdir\bin\scoop.ps1")) { + Remove-Item $newdir -Force -Recurse + abort "Scoop download failed. If this appears several times, try removing SCOOP_REPO by 'scoop config rm SCOOP_REPO'" + } else { + # replace non-git scoop with the git version + try { + Rename-Item $currentdir 'old' -ErrorAction Stop + Rename-Item $newdir 'current' -ErrorAction Stop + } catch { + Write-Warning $_ + abort "Scoop update failed. Folder in use. Paste $newdir into $currentdir." + } } - - # replace non-git scoop with the git version - Remove-Item -r -force $currentdir -ea stop - Move-Item $newdir $currentdir } else { + if (Test-Path "$currentdir\..\old") { + Remove-Item "$currentdir\..\old" -Recurse -Force -ErrorAction SilentlyContinue + } + $previousCommit = git -C "$currentdir" rev-parse HEAD $currentRepo = git -C "$currentdir" config remote.origin.url $currentBranch = git -C "$currentdir" branch