Skip to content

Commit

Permalink
fix(update): Prevent uninstall when update (#4949)
Browse files Browse the repository at this point in the history
Co-authored-by: Rashil Gandhi <46838874+rashil2000@users.noreply.github.com>
Co-authored-by: Hsiao-nan Cheung <niheaven@gmail.com>
  • Loading branch information
3 people authored Jun 1, 2022
1 parent 2e52888 commit d6c6ddc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
25 changes: 18 additions & 7 deletions libexec/scoop-update.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d6c6ddc

Please sign in to comment.