Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- **installed:** Fix 'core/installed' that mark failed app as 'installed' ([#4650](https://github.com/ScoopInstaller/Scoop/issues/4650))
- **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))
- **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))

### Code Refactoring
Expand Down
21 changes: 15 additions & 6 deletions libexec/scoop-cleanup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,38 +35,47 @@ function cleanup($app, $global, $verbose, $cache) {
if ($cache) {
Remove-Item "$cachedir\$app#*" -Exclude "$app#$current_version#*"
}
$versions = Get-InstalledVersion -AppName $app -Global:$global | Where-Object { $_ -ne $current_version -and $_ -ne 'current' }
$appDir = appdir $app $global
$versions = Get-ChildItem $appDir -Name
if (!$versions) {
Remove-Item $appDir -ErrorAction SilentlyContinue -Force
return
}
$versions = $versions | Where-Object { $_ -ne $current_version -and $_ -ne 'current' }
if (!$versions) {
if ($verbose) { success "$app is already clean" }
return
}

write-host -f yellow "Removing $app`:" -nonewline
Write-Host -f yellow "Removing $app`:" -NoNewline
$versions | ForEach-Object {
$version = $_
write-host " $version" -nonewline
Write-Host " $version" -NoNewline
$dir = versiondir $app $version $global
# unlink all potential old link before doing recursive Remove-Item
unlink_persist_data $dir
Remove-Item $dir -ErrorAction Stop -Recurse -Force
}
write-host ''
if (!(Get-ChildItem $appDir)) {
Remove-Item $appDir -ErrorAction SilentlyContinue -Force
}
Write-Host ''
}

if ($apps) {
$verbose = $true
if ($apps -eq '*') {
$verbose = $false
$apps = applist (installed_apps $false) $false
if ($global) {
$apps += applist (installed_apps $true) $true
}
} else {
$verbose = $true
$apps = Confirm-InstallationStatus $apps -Global:$global
}

# $apps is now a list of ($app, $global) tuples
$apps | ForEach-Object { cleanup @_ $verbose $cache}
$apps | ForEach-Object { cleanup @_ $verbose $cache }

if ($cache) {
Remove-Item "$cachedir\*.download" -ErrorAction Ignore
Expand Down