Skip to content

Commit

Permalink
fix(database): Use Find-BucketDirectory() to locate bucket dir
Browse files Browse the repository at this point in the history
  • Loading branch information
niheaven committed May 10, 2024
1 parent edaae8d commit 3818f58
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/buckets.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ function add_bucket($name, $repo) {
Write-Host 'OK'
if (get_config USE_SQLITE_CACHE) {
info 'Updating cache...'
Set-ScoopDB -Path (Get-ChildItem -Path $dir -Filter '*.json' -Recurse).FullName
Set-ScoopDB -Path (Get-ChildItem (Find-BucketDirectory $name) -Filter '*.json' -Recurse).FullName
}
success "The $name bucket was added successfully."
return 0
Expand Down
4 changes: 2 additions & 2 deletions lib/database.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,10 @@ function Set-ScoopDB {
}
process {
if ($Path.Count -eq 0) {
$bucketPath = Get-LocalBucket | ForEach-Object { Join-Path $bucketsdir $_ }
$bucketPath = Get-LocalBucket | ForEach-Object { Find-BucketDirectory $_ }
$Path = (Get-ChildItem $bucketPath -Filter '*.json' -Recurse).FullName
}
$Path | Where-Object { $_ -notmatch '[\\/]\.|[\\/]deprecated[\\/]' } | ForEach-Object {
$Path | ForEach-Object {
$manifestRaw = [System.IO.File]::ReadAllText($_)
$manifest = ConvertFrom-Json $manifestRaw -ErrorAction SilentlyContinue
if ($null -ne $manifest.version) {
Expand Down
25 changes: 15 additions & 10 deletions libexec/scoop-update.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -186,38 +186,43 @@ function Sync-Bucket {
# Parallel parameter is available since PowerShell 7
$buckets | Where-Object { $_.valid } | ForEach-Object -ThrottleLimit 5 -Parallel {
. "$using:PSScriptRoot\..\lib\core.ps1"
. "$using:PSScriptRoot\..\lib\buckets.ps1"

$bucketLoc = $_.path
$name = $_.name
$bucketLoc = $_.path
$innerBucketLoc = Find-BucketDirectory $name

$previousCommit = Invoke-Git -Path $bucketLoc -ArgumentList @('rev-parse', 'HEAD')
Invoke-Git -Path $bucketLoc -ArgumentList @('pull', '-q')
if ($using:Log) {
Invoke-GitLog -Path $bucketLoc -Name $name -CommitHash $previousCommit
}
if (get_config USE_SQLITE_CACHE) {
Invoke-Git -Path $bucketLoc -ArgumentList @('diff', '--name-only', '--diff-filter=d', $previousCommit) | Where-Object {
$_ -match '^[^.].*\.json$'
} | ForEach-Object {
[void]($using:updatedFiles).Add($(Join-Path $bucketLoc $_))
Invoke-Git -Path $bucketLoc -ArgumentList @('diff', '--name-only', '--diff-filter=d', $previousCommit) | ForEach-Object {
$filePath = Join-Path $bucketLoc $_
if ($filePath -match "^$([regex]::Escape($innerBucketLoc)).*\.json$") {
[void]($using:updatedFiles).Add($filePath)
}
}
}
}
} else {
$buckets | Where-Object { $_.valid } | ForEach-Object {
$bucketLoc = $_.path
$name = $_.name
$bucketLoc = $_.path
$innerBucketLoc = Find-BucketDirectory $name

$previousCommit = Invoke-Git -Path $bucketLoc -ArgumentList @('rev-parse', 'HEAD')
Invoke-Git -Path $bucketLoc -ArgumentList @('pull', '-q')
if ($Log) {
Invoke-GitLog -Path $bucketLoc -Name $name -CommitHash $previousCommit
}
if (get_config USE_SQLITE_CACHE) {
Invoke-Git -Path $bucketLoc -ArgumentList @('diff', '--name-only', '--diff-filter=d', $previousCommit) | Where-Object {
$_ -match '^[^.].*\.json$'
} | ForEach-Object {
[void]($updatedFiles).Add($(Join-Path $bucketLoc $_))
Invoke-Git -Path $bucketLoc -ArgumentList @('diff', '--name-only', '--diff-filter=d', $previousCommit) | ForEach-Object {
$filePath = Join-Path $bucketLoc $_
if ($filePath -match "^$([regex]::Escape($innerBucketLoc)).*\.json$") {
[void]($updatedFiles).Add($filePath)
}
}
}
}
Expand Down

0 comments on commit 3818f58

Please sign in to comment.