Skip to content

Commit ba970d5

Browse files
authored
fix(versions): Get current version from failed installation if possible (#4720)
1 parent e450843 commit ba970d5

7 files changed

+34
-18
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
- **shim:** Fix PS1 shim error when in different drive in PS7 ([#4614](https://github.com/ScoopInstaller/Scoop/issues/4614))
2424
- **shim:** Fix `sh` shim error in WSL ([#4637](https://github.com/ScoopInstaller/Scoop/issues/4637))
2525
- **versions:** Fix wrong version number when only one version dir ([#4679](https://github.com/ScoopInstaller/Scoop/issues/4679))
26+
- **versions:** Get current version from failed installation if possible ([#4720](https://github.com/ScoopInstaller/Scoop/issues/4720))
2627
- **scoop-cleanup:** Remove apps other than current version ([#4665](https://github.com/ScoopInstaller/Scoop/issues/4665))
2728
- **scoop-update:** Skip updating non git buckets ([#4670](https://github.com/ScoopInstaller/Scoop/issues/4670))
2829
- **scoop-update:** Remove 'Done.' output ([#4672](https://github.com/ScoopInstaller/Scoop/issues/4672))

lib/core.ps1

+4-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,10 @@ function installed_apps($global) {
210210

211211
# check whether the app failed to install
212212
function failed($app, $global) {
213-
return (is_directory (appdir $app $global)) -and !(Select-CurrentVersion -AppName $app -Global:$global)
213+
$app = ($app -split '/|\\')[-1]
214+
$appPath = appdir $app $global
215+
$hasCurrent = (get_config NO_JUNCTIONS) -or (Test-Path "$appPath\current")
216+
return (Test-Path $appPath) -and !($hasCurrent -and (installed $app $global))
214217
}
215218

216219
function file_path($app, $file) {

lib/install.ps1

+11-4
Original file line numberDiff line numberDiff line change
@@ -1077,12 +1077,19 @@ function prune_installed($apps, $global) {
10771077
return @($uninstalled), @($installed)
10781078
}
10791079

1080-
function ensure_none_failed($apps, $global) {
1080+
function ensure_none_failed($apps) {
10811081
foreach ($app in $apps) {
10821082
$app = ($app -split '/|\\')[-1] -replace '\.json$', ''
1083-
if (failed $app $global) {
1084-
warn "Purging previous failed installation of $app."
1085-
& "$PSScriptRoot\..\libexec\scoop-uninstall.ps1" $app$(if ($global) { ' --global' })
1083+
foreach ($global in $true, $false) {
1084+
if (failed $app $global) {
1085+
if (installed $app $global) {
1086+
warn "Repair previous failed installation of $app."
1087+
& "$PSScriptRoot\..\libexec\scoop-reset.ps1" $app$(if ($global) { ' --global' })
1088+
} else {
1089+
warn "Purging previous failed installation of $app."
1090+
& "$PSScriptRoot\..\libexec\scoop-uninstall.ps1" $app$(if ($global) { ' --global' })
1091+
}
1092+
}
10861093
}
10871094
}
10881095
}

lib/versions.ps1

+8-7
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,20 @@ function Select-CurrentVersion {
5050
$Global
5151
)
5252
process {
53-
$appPath = appdir $AppName $Global
54-
if (get_config NO_JUNCTIONS) {
53+
$currentPath = "$(appdir $AppName $Global)\current"
54+
if (!(get_config NO_JUNCTIONS)) {
55+
$currentVersion = (parse_json "$currentPath\manifest.json").version
56+
if ($currentVersion -eq 'nightly') {
57+
$currentVersion = (Get-Item $currentPath).Target | Split-Path -Leaf
58+
}
59+
}
60+
if ($null -eq $currentVersion) {
5561
$installedVersion = Get-InstalledVersion -AppName $AppName -Global:$Global
5662
if ($installedVersion) {
5763
$currentVersion = @($installedVersion)[-1]
5864
} else {
5965
$currentVersion = $null
6066
}
61-
} else {
62-
$currentVersion = (installed_manifest $AppName 'current' $Global).version
63-
if ($currentVersion -eq 'nightly') {
64-
$currentVersion = (Get-Item "$appPath\current").Target | Split-Path -Leaf
65-
}
6667
}
6768
return $currentVersion
6869
}

libexec/scoop-install.ps1

+3-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ if (is_scoop_outdated) {
5959
}
6060
}
6161

62+
ensure_none_failed $apps
63+
6264
if ($apps.length -eq 1) {
6365
$app, $null, $version = parse_app $apps
6466
if ($app.EndsWith('.json')) {
@@ -102,7 +104,7 @@ $explicit_apps = $apps
102104
if (!$independent) {
103105
$apps = $apps | Get-Dependency -Architecture $architecture | Select-Object -Unique # adds dependencies
104106
}
105-
ensure_none_failed $apps $global
107+
ensure_none_failed $apps
106108

107109
$apps, $skip = prune_installed $apps $global
108110

libexec/scoop-list.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ $apps | Where-Object { !$query -or ($_.name -match $query) } | ForEach-Object {
4444

4545
$info = @()
4646
if($global) { $info += "Global install" }
47-
if (!$install_info) { $info += "Install failed" }
47+
if (failed $app $global) { $info += "Install failed" }
4848
if ($install_info.hold) { $info += "Held package" }
4949
if ($install_info.architecture -and $def_arch -ne $install_info.architecture) {
5050
$info += $install_info.architecture

libexec/scoop-update.ps1

+6-4
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,9 @@ function update($app, $global, $quiet = $false, $independent, $suggested, $use_c
274274
install_app $app $architecture $global $suggested $use_cache $check_hash
275275
} else {
276276
# Also add missing dependencies
277-
$apps = Get-Dependency $app $architecture | Where-Object { !(installed $_) }
278-
$apps | ForEach-Object { install_app $_ $architecture $global $suggested $use_cache $check_hash }
277+
$apps = (Get-Dependency $app $architecture) -ne $app
278+
ensure_none_failed $apps
279+
@($apps) + $app | Where-Object { !(installed $_) } | ForEach-Object { install_app $_ $architecture $global $suggested $use_cache $check_hash }
279280
}
280281
}
281282

@@ -311,14 +312,15 @@ if (-not ($apps -or $all)) {
311312
($app, $global) = $_
312313
$status = app_status $app $global
313314
if ($status.installed -and ($force -or $status.outdated)) {
314-
if(!$status.hold) {
315+
if (!$status.hold) {
315316
$outdated += applist $app $global
316-
Write-Host -f yellow ("$app`: $($status.version) -> $($status.latest_version){0}" -f ('',' (global)')[$global])
317+
Write-Host -f yellow ("$app`: $($status.version) -> $($status.latest_version){0}" -f ('', ' (global)')[$global])
317318
} else {
318319
warn "'$app' is held to version $($status.version)"
319320
}
320321
} elseif ($apps_param -ne '*') {
321322
if ($status.installed) {
323+
ensure_none_failed $app $global
322324
Write-Host "$app`: $($status.version) (latest version)" -ForegroundColor Green
323325
} else {
324326
info 'Please reinstall it or fix the manifest.'

0 commit comments

Comments
 (0)