From 3818f5829a6ad73d8d1e0255745468f53ea4e25c Mon Sep 17 00:00:00 2001 From: Hsiao-nan Cheung Date: Fri, 10 May 2024 10:14:58 +0800 Subject: [PATCH] fix(database): Use `Find-BucketDirectory()` to locate bucket dir --- lib/buckets.ps1 | 2 +- lib/database.ps1 | 4 ++-- libexec/scoop-update.ps1 | 25 +++++++++++++++---------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/lib/buckets.ps1 b/lib/buckets.ps1 index ca12684ca6..2adac4f339 100644 --- a/lib/buckets.ps1 +++ b/lib/buckets.ps1 @@ -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 diff --git a/lib/database.ps1 b/lib/database.ps1 index 5e329cd687..e15720d7da 100644 --- a/lib/database.ps1 +++ b/lib/database.ps1 @@ -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) { diff --git a/libexec/scoop-update.ps1 b/libexec/scoop-update.ps1 index fdcf8707a3..79bd706a65 100644 --- a/libexec/scoop-update.ps1 +++ b/libexec/scoop-update.ps1 @@ -186,9 +186,11 @@ 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') @@ -196,17 +198,19 @@ function Sync-Bucket { 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') @@ -214,10 +218,11 @@ function Sync-Bucket { 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) + } } } }