From cd49d0e37c5875a4889d812b2524b34abcb68633 Mon Sep 17 00:00:00 2001 From: Richard Kuhnt Date: Thu, 2 Mar 2017 21:01:54 +0100 Subject: [PATCH 1/2] Better error handling for autoupdate and checkver do_dl() now rethrows an exception instead of aborting. this prevents killing the autoupdate process prematurely and thus skipping queued updates. --- bin/checkver.ps1 | 3 +- lib/autoupdate.ps1 | 72 ++++++++++++++++++++++++++++++---------------- lib/install.ps1 | 9 ++++-- 3 files changed, 56 insertions(+), 28 deletions(-) diff --git a/bin/checkver.ps1 b/bin/checkver.ps1 index 70c83059..7f839f5e 100644 --- a/bin/checkver.ps1 +++ b/bin/checkver.ps1 @@ -106,7 +106,8 @@ while($in_progress -gt 0) { write-host "$app`: " -nonewline if($err) { - write-host "ERROR: $err" -f darkyellow + write-host -f darkred $err.message + write-host -f darkred "URL $url is not valid" } else { if($page -match $regexp) { $ver = $matches[1] diff --git a/lib/autoupdate.ps1 b/lib/autoupdate.ps1 index 243490b1..b0f97ef4 100644 --- a/lib/autoupdate.ps1 +++ b/lib/autoupdate.ps1 @@ -23,9 +23,12 @@ function check_url([String] $url) { return $true } - $response = Invoke-WebRequest -Uri $url -Method HEAD - if ($response.StatusCode.Equals(200)) { # redirects might be ok - return $true + try { + $response = Invoke-WebRequest -Uri $url -Method HEAD + return ($response -and $response.StatusCode.Equals(200)) # redirects might be ok + } catch [system.net.webexception] { + write-host -f darkred $_ + write-host -f darkred "URL $url is not valid" } return $false @@ -36,8 +39,15 @@ function find_hash_in_rdf([String] $url, [String] $filename) Write-Host -f DarkYellow "RDF URL: $url" Write-Host -f DarkYellow "File: $filename" - # Download and parse RDF XML file - [xml]$data = (new-object net.webclient).downloadstring($url) + $data = "" + try { + # Download and parse RDF XML file + [xml]$data = (new-object net.webclient).downloadstring($url) + } catch [system.net.webexception] { + write-host -f darkred $_ + write-host -f darkred "URL $url is not valid" + return $null + } # Find file content $digest = $data.RDF.Content | ? { [String]$_.about -eq $filename } @@ -60,7 +70,15 @@ function get_hash_for_app([String] $app, $config, [String] $version, [String] $u if ($hashmode -eq "extract") { $hashfile_url = substitute $config.url @{'$url' = $url} $hashfile_url = substitute $hashfile_url $substitutions - $hashfile = (new-object net.webclient).downloadstring($hashfile_url) + $hashfile = $null + + try { + $hashfile = (new-object net.webclient).downloadstring($hashfile_url) + } catch [system.net.webexception] { + write-host -f darkred $_ + write-host -f darkred "URL $hashfile_url is not valid" + return $null + } $regex = $config.find if ($regex -eq $null) { @@ -81,7 +99,13 @@ function get_hash_for_app([String] $app, $config, [String] $version, [String] $u return find_hash_in_rdf $config.url $basename } else { Write-Host "Download files to compute hashes!" -f DarkYellow - dl_with_cache $app $version $url $null $null $true + try { + dl_with_cache $app $version $url $null $null $true + } catch [system.net.webexception] { + write-host -f darkred $_ + write-host -f darkred "URL $url is not valid" + return $null + } $file = fullpath (cache_path $app $version $url) return compute_hash $file "sha256" } @@ -164,16 +188,15 @@ function autoupdate([String] $app, $dir, $json, [String] $version, [Hashtable] $ $url = substitute $json.autoupdate.url $substitutions # check url - if (!(check_url $url)) { - $valid = $false - Write-Host -f DarkRed "URL $url is not valid" - } + $valid = check_url $url - # create hash - $hash = get_hash_for_app $app $json.autoupdate.hash $version $url $substitutions - if ($hash -eq $null) { - $valid = $false - Write-Host -f DarkRed "Could not find hash!" + if($valid) { + # create hash + $hash = get_hash_for_app $app $json.autoupdate.hash $version $url $substitutions + if ($hash -eq $null) { + $valid = $false + Write-Host -f DarkRed "Could not find hash!" + } } # write changes to the json object @@ -193,16 +216,15 @@ function autoupdate([String] $app, $dir, $json, [String] $version, [Hashtable] $ $url = substitute (arch_specific "url" $json.autoupdate $architecture) $substitutions # check url - if (!(check_url $url)) { - $valid = $false - Write-Host -f DarkRed "URL $url is not valid" - } + $valid = check_url $url - # create hash - $hash = get_hash_for_app $app (arch_specific "hash" $json.autoupdate $architecture) $version $url $substitutions - if ($hash -eq $null) { - $valid = $false - Write-Host -f DarkRed "Could not find hash!" + if($valid) { + # create hash + $hash = get_hash_for_app $app (arch_specific "hash" $json.autoupdate $architecture) $version $url $substitutions + if ($hash -eq $null) { + $valid = $false + Write-Host -f DarkRed "Could not find hash!" + } } # write changes to the json object diff --git a/lib/install.ps1 b/lib/install.ps1 index fe2ffebe..34e19c51 100644 --- a/lib/install.ps1 +++ b/lib/install.ps1 @@ -142,7 +142,7 @@ function do_dl($url, $to, $cookies) { } catch { $e = $_.exception if($e.innerexception) { $e = $e.innerexception } - abort $e.message + throw $e } finally { set_https_protocols $original_protocols } @@ -300,7 +300,12 @@ function dl_urls($app, $version, $manifest, $architecture, $dir, $use_cache = $t } $fname = $data.$url.fname - dl_with_cache $app $version $url "$dir\$fname" $cookies $use_cache + try { + dl_with_cache $app $version $url "$dir\$fname" $cookies $use_cache + } catch { + write-host -f darkred $_ + abort "URL $url is not valid" + } } foreach($url in $urls) { From 0c7909f615d49c86c9149503f5c72631682dcf3f Mon Sep 17 00:00:00 2001 From: Richard Kuhnt Date: Thu, 2 Mar 2017 23:10:52 +0100 Subject: [PATCH 2/2] Remove _comment from openssl --- bucket/openssl.json | 1 - 1 file changed, 1 deletion(-) diff --git a/bucket/openssl.json b/bucket/openssl.json index 2e9cc10c..daa3c300 100644 --- a/bucket/openssl.json +++ b/bucket/openssl.json @@ -2,7 +2,6 @@ "homepage": "https://slproweb.com/products/Win32OpenSSL.html", "version": "1.1.0e", "license": "https://www.openssl.org/source/license.html", - "_comment": "Hashes at https://slproweb.com/download/win32_openssl_hashes.json", "architecture": { "64bit": { "url": "https://slproweb.com/download/Win64OpenSSL-1_1_0e.exe",