Skip to content

Commit

Permalink
fix(versions): Get current version from failed installation if possib…
Browse files Browse the repository at this point in the history
  • Loading branch information
niheaven authored Feb 9, 2022
1 parent e450843 commit ba970d5
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
- **shim:** Fix PS1 shim error when in different drive in PS7 ([#4614](https://github.com/ScoopInstaller/Scoop/issues/4614))
- **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-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))
Expand Down
5 changes: 4 additions & 1 deletion lib/core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,10 @@ function installed_apps($global) {

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

function file_path($app, $file) {
Expand Down
15 changes: 11 additions & 4 deletions lib/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1077,12 +1077,19 @@ function prune_installed($apps, $global) {
return @($uninstalled), @($installed)
}

function ensure_none_failed($apps, $global) {
function ensure_none_failed($apps) {
foreach ($app in $apps) {
$app = ($app -split '/|\\')[-1] -replace '\.json$', ''
if (failed $app $global) {
warn "Purging previous failed installation of $app."
& "$PSScriptRoot\..\libexec\scoop-uninstall.ps1" $app$(if ($global) { ' --global' })
foreach ($global in $true, $false) {
if (failed $app $global) {
if (installed $app $global) {
warn "Repair previous failed installation of $app."
& "$PSScriptRoot\..\libexec\scoop-reset.ps1" $app$(if ($global) { ' --global' })
} else {
warn "Purging previous failed installation of $app."
& "$PSScriptRoot\..\libexec\scoop-uninstall.ps1" $app$(if ($global) { ' --global' })
}
}
}
}
}
Expand Down
15 changes: 8 additions & 7 deletions lib/versions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,20 @@ function Select-CurrentVersion {
$Global
)
process {
$appPath = appdir $AppName $Global
if (get_config NO_JUNCTIONS) {
$currentPath = "$(appdir $AppName $Global)\current"
if (!(get_config NO_JUNCTIONS)) {
$currentVersion = (parse_json "$currentPath\manifest.json").version
if ($currentVersion -eq 'nightly') {
$currentVersion = (Get-Item $currentPath).Target | Split-Path -Leaf
}
}
if ($null -eq $currentVersion) {
$installedVersion = Get-InstalledVersion -AppName $AppName -Global:$Global
if ($installedVersion) {
$currentVersion = @($installedVersion)[-1]
} else {
$currentVersion = $null
}
} else {
$currentVersion = (installed_manifest $AppName 'current' $Global).version
if ($currentVersion -eq 'nightly') {
$currentVersion = (Get-Item "$appPath\current").Target | Split-Path -Leaf
}
}
return $currentVersion
}
Expand Down
4 changes: 3 additions & 1 deletion libexec/scoop-install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ if (is_scoop_outdated) {
}
}

ensure_none_failed $apps

if ($apps.length -eq 1) {
$app, $null, $version = parse_app $apps
if ($app.EndsWith('.json')) {
Expand Down Expand Up @@ -102,7 +104,7 @@ $explicit_apps = $apps
if (!$independent) {
$apps = $apps | Get-Dependency -Architecture $architecture | Select-Object -Unique # adds dependencies
}
ensure_none_failed $apps $global
ensure_none_failed $apps

$apps, $skip = prune_installed $apps $global

Expand Down
2 changes: 1 addition & 1 deletion libexec/scoop-list.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ $apps | Where-Object { !$query -or ($_.name -match $query) } | ForEach-Object {

$info = @()
if($global) { $info += "Global install" }
if (!$install_info) { $info += "Install failed" }
if (failed $app $global) { $info += "Install failed" }
if ($install_info.hold) { $info += "Held package" }
if ($install_info.architecture -and $def_arch -ne $install_info.architecture) {
$info += $install_info.architecture
Expand Down
10 changes: 6 additions & 4 deletions libexec/scoop-update.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,9 @@ 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 | Where-Object { !(installed $_) }
$apps | ForEach-Object { install_app $_ $architecture $global $suggested $use_cache $check_hash }
$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 }
}
}

Expand Down Expand Up @@ -311,14 +312,15 @@ if (-not ($apps -or $all)) {
($app, $global) = $_
$status = app_status $app $global
if ($status.installed -and ($force -or $status.outdated)) {
if(!$status.hold) {
if (!$status.hold) {
$outdated += applist $app $global
Write-Host -f yellow ("$app`: $($status.version) -> $($status.latest_version){0}" -f ('',' (global)')[$global])
Write-Host -f yellow ("$app`: $($status.version) -> $($status.latest_version){0}" -f ('', ' (global)')[$global])
} else {
warn "'$app' is held to version $($status.version)"
}
} elseif ($apps_param -ne '*') {
if ($status.installed) {
ensure_none_failed $app $global
Write-Host "$app`: $($status.version) (latest version)" -ForegroundColor Green
} else {
info 'Please reinstall it or fix the manifest.'
Expand Down

0 comments on commit ba970d5

Please sign in to comment.