From 79bca95ffc565e1b19b72e8148c0577de2c6bcbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C4=8C=C3=A1bera?= Date: Sun, 8 Aug 2021 18:58:43 +0200 Subject: [PATCH 1/4] fix(checkver): URL ping equality with dl function --- lib/autoupdate.ps1 | 2 ++ lib/core.ps1 | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/autoupdate.ps1 b/lib/autoupdate.ps1 index e599020359..847a99fbf8 100644 --- a/lib/autoupdate.ps1 +++ b/lib/autoupdate.ps1 @@ -259,6 +259,8 @@ function get_hash_for_app([String] $app, $config, [String] $version, [String] $u Write-Host ' to verify URL accessibility' -ForegroundColor 'Yellow' $request = [System.Net.WebRequest]::Create($url) # TODO: Consider spliting #/ from URL to prevent potential faulty response $request.AllowAutoRedirect = $true + $request.Headers.Add('Referer', (strip_filename $url)) + $request.Headers.Add('User-Agent', $SHOVEL_USERAGENT) try { $response = $request.GetResponse() $response.Close() diff --git a/lib/core.ps1 b/lib/core.ps1 index ff84b46343..2334f88be8 100644 --- a/lib/core.ps1 +++ b/lib/core.ps1 @@ -628,9 +628,9 @@ function Invoke-ExternalCommand { function dl($url, $to) { $wc = New-Object System.Net.Webclient - $wc.headers.add('Referer', (strip_filename $url)) + $wc.Headers.Add('Referer', (strip_filename $url)) $wc.Headers.Add('User-Agent', $SHOVEL_USERAGENT) - $wc.downloadFile($url, $to) + $wc.DownloadFile($url, $to) } function env($name, $global, $val = '__get') { From d6b6b9bc3d41fd547c88d692f0e5bb99d1d57167 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C4=8C=C3=A1bera?= Date: Sun, 8 Aug 2021 19:19:26 +0200 Subject: [PATCH 2/4] debug --- lib/manifest.ps1 | 2 ++ test/Shovel-Manifest.Tests.ps1 | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/manifest.ps1 b/lib/manifest.ps1 index c38730aea7..498fe8ccb5 100644 --- a/lib/manifest.ps1 +++ b/lib/manifest.ps1 @@ -135,6 +135,8 @@ function New-VersionedManifest { $newManifest = Invoke-Autoupdate $Path.Basename $null $manifest $Version $(${ }) $Path.Extension -IgnoreArchive if ($null -eq $newManifest) { throw 'trigger' } } catch { + Write-Host $_.Exception.InnerException.Message -f magenta + Write-Host $_.Exception.Message -f magenta throw [ScoopException] "Cannot generate manifest with version '$Version'" } diff --git a/test/Shovel-Manifest.Tests.ps1 b/test/Shovel-Manifest.Tests.ps1 index 56bfee004e..4271e9b207 100644 --- a/test/Shovel-Manifest.Tests.ps1 +++ b/test/Shovel-Manifest.Tests.ps1 @@ -58,6 +58,7 @@ Describe 'Manifests operations' -Tag 'Scoop' { It 'New-VersionedManifest' { $path = manifest_path 'pwsh' 'ash258.ash258' + Write-Host -f magenta $SHOVEL_USERAGENT $new = New-VersionedManifest -LiteralPath $path -Version '7.1.0' 6>$null $new | Should -BeLike "$env:SCOOP\manifests\pwsh-*.json" (ConvertFrom-Manifest -LiteralPath $new).version | Should -Be '7.1.0' @@ -126,7 +127,7 @@ Describe 'Manifests operations' -Tag 'Scoop' { It 'Error handling' { { manifest_path 'invalid_wget' 'main' | Resolve-ManifestInformation } | Should -Throw 'Not a valid manifest' - ( { manifest_path 'broken_wget' 'main' | Resolve-ManifestInformation } | Should -Throw -Passthru).Exception.Message | Should -BeLike 'File is not a valid manifest*' + ( { manifest_path 'broken_wget' 'main' | Resolve-ManifestInformation } | Should -Throw -PassThru).Exception.Message | Should -BeLike 'File is not a valid manifest*' } } From d582bee5f2849965b19ee99095c12f617d0ad3fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C4=8C=C3=A1bera?= Date: Sun, 8 Aug 2021 19:31:14 +0200 Subject: [PATCH 3/4] fix powershell 5 fluke --- lib/autoupdate.ps1 | 9 +++++++-- lib/manifest.ps1 | 2 -- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/autoupdate.ps1 b/lib/autoupdate.ps1 index 847a99fbf8..991c9a2775 100644 --- a/lib/autoupdate.ps1 +++ b/lib/autoupdate.ps1 @@ -259,8 +259,13 @@ function get_hash_for_app([String] $app, $config, [String] $version, [String] $u Write-Host ' to verify URL accessibility' -ForegroundColor 'Yellow' $request = [System.Net.WebRequest]::Create($url) # TODO: Consider spliting #/ from URL to prevent potential faulty response $request.AllowAutoRedirect = $true - $request.Headers.Add('Referer', (strip_filename $url)) - $request.Headers.Add('User-Agent', $SHOVEL_USERAGENT) + if ($PSVersionTable.PSVersion.Major -lt 6) { + $request.UserAgent = $SHOVEL_USERAGENT + $request.Referer = strip_filename $url + } else { + $request.Headers.Add('Referer', (strip_filename $url)) + $request.Headers.Add('User-Agent', $SHOVEL_USERAGENT) + } try { $response = $request.GetResponse() $response.Close() diff --git a/lib/manifest.ps1 b/lib/manifest.ps1 index 498fe8ccb5..c38730aea7 100644 --- a/lib/manifest.ps1 +++ b/lib/manifest.ps1 @@ -135,8 +135,6 @@ function New-VersionedManifest { $newManifest = Invoke-Autoupdate $Path.Basename $null $manifest $Version $(${ }) $Path.Extension -IgnoreArchive if ($null -eq $newManifest) { throw 'trigger' } } catch { - Write-Host $_.Exception.InnerException.Message -f magenta - Write-Host $_.Exception.Message -f magenta throw [ScoopException] "Cannot generate manifest with version '$Version'" } From 9f6e2d723bc1d4f6aadaaf01909b6a98af27bde7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C4=8C=C3=A1bera?= Date: Sun, 8 Aug 2021 19:31:58 +0200 Subject: [PATCH 4/4] debug --- test/Shovel-Manifest.Tests.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/test/Shovel-Manifest.Tests.ps1 b/test/Shovel-Manifest.Tests.ps1 index 4271e9b207..a208d38813 100644 --- a/test/Shovel-Manifest.Tests.ps1 +++ b/test/Shovel-Manifest.Tests.ps1 @@ -58,7 +58,6 @@ Describe 'Manifests operations' -Tag 'Scoop' { It 'New-VersionedManifest' { $path = manifest_path 'pwsh' 'ash258.ash258' - Write-Host -f magenta $SHOVEL_USERAGENT $new = New-VersionedManifest -LiteralPath $path -Version '7.1.0' 6>$null $new | Should -BeLike "$env:SCOOP\manifests\pwsh-*.json" (ConvertFrom-Manifest -LiteralPath $new).version | Should -Be '7.1.0'