diff --git a/lib/core.ps1 b/lib/core.ps1 index 139e579c92..43cb9d1523 100644 --- a/lib/core.ps1 +++ b/lib/core.ps1 @@ -443,9 +443,6 @@ function app_status($app, $global) { return $status } -# TODO: YAML -function appname_from_url($url) { return (Split-Path $url -Leaf) -replace '\.json$' } - # paths function fname($path) { return Split-Path $path -Leaf } function strip_ext($fname) { return $fname -replace '\.[^\.]*$' } @@ -1157,6 +1154,9 @@ $SCOOP_GLOBAL_ROOT_DIRECTORY = $env:SCOOP_GLOBAL, "$env:ProgramData\scoop" | Whe # Use at your own risk. $SCOOP_CACHE_DIRECTORY = $env:SCOOP_CACHE, "$SCOOP_ROOT_DIRECTORY\cache" | Where-Object { -not [String]::IsNullOrEmpty($_) } | Select-Object -First 1 +# Directory for downloaded manifests (mainly) +$SHOVEL_GENERAL_MANIFESTS_DIRECTORY = Join-Path $SCOOP_ROOT_DIRECTORY 'manifests' + # Load Scoop config $configHome = $env:XDG_CONFIG_HOME, "$env:USERPROFILE\.config" | Where-Object { -not [String]::IsNullOrEmpty($_) } | Select-Object -First 1 $SCOOP_CONFIGURATION_FILE = Join-Path $configHome 'scoop\config.json' diff --git a/lib/manifest.ps1 b/lib/manifest.ps1 index 75291af716..5b94187e04 100644 --- a/lib/manifest.ps1 +++ b/lib/manifest.ps1 @@ -97,10 +97,14 @@ function ConvertTo-Manifest { } } -function manifest_path($app, $bucket) { +# TODO: YAML +function appname_from_url($url) { return (Split-Path $url -Leaf) -replace '\.json$' } + +function manifest_path($app, $bucket, $version = $null) { $name = sanitary_path $app $buc = Find-BucketDirectory -Bucket $bucket $path = $file = $null + try { $file = Get-ChildItem -LiteralPath $buc -Filter "$name.*" -ErrorAction 'Stop' } catch { @@ -110,6 +114,22 @@ function manifest_path($app, $bucket) { if ($file) { if ($file.Count -gt 1) { $file = $file[0] } $path = $file.FullName + + # Look for archived version only if manifest exists + if ($version) { + $path = $null + $versions = @() + + try { + $versions = Get-ChildItem -LiteralPath "$buc\old\$name" -Filter "$version.*" -ErrorAction 'Stop' + } catch { + throw [ScoopException] "Bucket '$bucket' does not contain archived version '$version' for '$app'" + } + + if ($versions.Count -gt 1) { $versions = $versions[0] } + + $path = $versions.FullName + } } return $path diff --git a/test/Shovel-Manifest.Tests.ps1 b/test/Shovel-Manifest.Tests.ps1 new file mode 100644 index 0000000000..704e7e0fe5 --- /dev/null +++ b/test/Shovel-Manifest.Tests.ps1 @@ -0,0 +1,58 @@ + +. "$PSScriptRoot\Scoop-TestLib.ps1" +. "$PSScriptRoot\..\lib\core.ps1" +. "$PSScriptRoot\..\lib\manifest.ps1" + +Describe 'Resolve-ManifestInformation' -Tag 'Scoop' { + BeforeAll { + $working_dir = (setup_working 'manifest' | Resolve-Path).Path + Move-Item "$working_dir\*.*" "$working_dir\bucket" + $SCOOP_BUCKETS_DIRECTORY = $working_dir | Split-Path + + Copy-Item $working_dir "$SCOOP_BUCKETS_DIRECTORY\ash258.ash258" -Force -Recurse + Copy-Item $working_dir "$SCOOP_BUCKETS_DIRECTORY\main" -Force -Recurse + } + + It 'manifest_path' { + $path = manifest_path 'cosi' 'manifest' + $path | Should -Be "$working_dir\bucket\cosi.yaml" + $path = $null + + $path = manifest_path 'wget' 'manifest' + $path | Should -Be "$working_dir\bucket\wget.json" + $path = $null + + $path = manifest_path 'pwsh' 'ash258.ash258' + $path | Should -Be "$SCOOP_BUCKETS_DIRECTORY\ash258.ash258\bucket\pwsh.json" + $path = $null + + $path = manifest_path 'cosi' 'main' + $path | Should -Be "$SCOOP_BUCKETS_DIRECTORY\main\bucket\cosi.yaml" + $path = $null + + $path = manifest_path 'pwsh' 'alfa' + $path | Should -Be $null + $path = $null + + $path = manifest_path 'ahoj' 'main' + $path | Should -Be $null + $path = $null + } + + It 'manifest_path with version' { + $path = manifest_path 'cosi' 'main' '7.1.0' + $path | Should -Be "$SCOOP_BUCKETS_DIRECTORY\main\bucket\old\cosi\7.1.0.yaml" + $path = $null + + $path = manifest_path 'pwsh' 'ash258.ash258' '6.2.3' + $path | Should -Be "$SCOOP_BUCKETS_DIRECTORY\ash258.ash258\bucket\old\pwsh\6.2.3.yml" + $path = $null + + $path = manifest_path 'pwsh' 'ash258.ash258' '2222' + $path | Should -Be $null + $path = $null + + { manifest_path 'wget' 'ash258.ash258' '2222' } | Should -Throw 'Bucket ''ash258.ash258'' does not contain archived version ''2222'' for ''wget''' + $path = $null + } +} diff --git a/test/fixtures/manifest/bucket/cosi.yaml b/test/fixtures/manifest/bucket/cosi.yaml new file mode 100644 index 0000000000..c4ca74f049 --- /dev/null +++ b/test/fixtures/manifest/bucket/cosi.yaml @@ -0,0 +1,26 @@ +version: 7.1.3 +description: Cross-platform automation and configuration tool/framework, known as Powershell Core, that works well with existing tools and is optimized for dealing with structured data. +homepage: https://github.com/PowerShell/PowerShell +license: MIT +architecture: + 64bit: + url: https://github.com/PowerShell/PowerShell/releases/download/v7.1.3/PowerShell-7.1.3-win-x64.zip + hash: 47475f1d4015704f3fb5f6d2cf61196d121aba60c19592b04be818317ce01039 + 32bit: + url: https://github.com/PowerShell/PowerShell/releases/download/v7.1.3/PowerShell-7.1.3-win-x86.zip + hash: ecfd51545084d9b791874062c39eb0c7c7dd2991265ee7f4dc5064995a614e6c +bin: pwsh.exe +shortcuts: +- - pwsh.exe + - PowerShell Core +checkver: github +autoupdate: + archive: true + architecture: + 64bit: + url: https://github.com/PowerShell/PowerShell/releases/download/v$version/PowerShell-$version-win-x64.zip + 32bit: + url: https://github.com/PowerShell/PowerShell/releases/download/v$version/PowerShell-$version-win-x86.zip + hash: + url: https://github.com/PowerShell/PowerShell/releases/tag/v$version/ + regex: $basename\s*