Skip to content

Commit

Permalink
fix(bucket): Return empty list correctly in Get-LocalBucket
Browse files Browse the repository at this point in the history
  • Loading branch information
L. Yeung committed Apr 25, 2022
1 parent e6d0371 commit fda35f8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- **update:** Skip logs starting with `(chore)` ([#4800](https://github.com/ScoopInstaller/Scoop/issues/4800))
- **scoop-download:** Add failure check ([#4822](https://github.com/ScoopInstaller/Scoop/pull/4822))
- **install:** Fix issue with installation inside containers ([#4837](https://github.com/ScoopInstaller/Scoop/pull/4837))
- **bucket:** Return empty list correctly in `Get-LocalBucket` ([#4885](https://github.com/ScoopInstaller/Scoop/pull/4885))

### Performance Improvements

Expand Down
14 changes: 11 additions & 3 deletions lib/buckets.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@ function Get-LocalBucket {
.SYNOPSIS
List all local buckets.
#>

return (Get-ChildItem -Directory $bucketsdir).Name
$bucketNames = (Get-ChildItem -Directory $bucketsdir).Name
if (!$bucketNames.Length) {
return @() # Return a zero-length list instead of $null.
}
return $bucketNames
}

function buckets {
Expand Down Expand Up @@ -123,7 +126,12 @@ function Convert-RepositoryUri {

function list_buckets {
$buckets = @()
Get-LocalBucket | ForEach-Object {
$bucketNames = Get-LocalBucket
if (!$bucketNames.Length){
warn "No bucket found. Please run 'scoop bucket add main' to add the default 'main' bucket."
return
}
$bucketNames | ForEach-Object {
$bucket = [Ordered]@{ Name = $_ }
$path = Find-BucketDirectory $_ -Root
if ((Test-Path (Join-Path $path '.git')) -and (Get-Command git -ErrorAction SilentlyContinue)) {
Expand Down
2 changes: 1 addition & 1 deletion libexec/scoop-alias.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function list_aliases {
}

if (!$aliases.count) {
warn 'No aliases founds.'
info "No alias found."
}
$aliases = $aliases.GetEnumerator() | Sort-Object Name
if ($verbose) {
Expand Down
8 changes: 6 additions & 2 deletions libexec/scoop-cache.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ function cacheshow($app) {
$app = '(' + ($app -join '|') + ')'
}
$files = @(Get-ChildItem $cachedir | Where-Object -Property Name -Value "^$app#" -Match)
$totalLength = ($files | Measure-Object -Property Length -Sum).Sum

$files | ForEach-Object { cacheinfo $_ } | Select-Object Name, Version, Length, URL
if (!$files.Length) {
$totalLength = 0
} else {
$totalLength = ($files | Measure-Object -Property Length -Sum).Sum
$files | ForEach-Object { cacheinfo $_ } | Select-Object Name, Version, Length, URL
}

Write-Host "Total: $($files.Length) $(pluralize $files.Length 'file' 'files'), $(filesize $totalLength)" -ForegroundColor Yellow
}
Expand Down

0 comments on commit fda35f8

Please sign in to comment.