diff options
| author | Alexander Karatarakis <alkarata@microsoft.com> | 2018-04-05 03:16:22 -0700 |
|---|---|---|
| committer | Alexander Karatarakis <alkarata@microsoft.com> | 2018-04-06 17:24:46 -0700 |
| commit | 3a9be92f7e9cb867eaef4091ace282e4c8e82b92 (patch) | |
| tree | 9a44695fe4b762852318e3ae3271af279b6f3b4c /scripts/VcpkgPowershellUtils.ps1 | |
| parent | 5b78dfaf68d33c2444437f92d253d7fa912152ec (diff) | |
| download | vcpkg-3a9be92f7e9cb867eaef4091ace282e4c8e82b92.tar.gz vcpkg-3a9be92f7e9cb867eaef4091ace282e4c8e82b92.zip | |
[fetchTool.ps1] Move downloaded file in place after hash check
Diffstat (limited to 'scripts/VcpkgPowershellUtils.ps1')
| -rw-r--r-- | scripts/VcpkgPowershellUtils.ps1 | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/scripts/VcpkgPowershellUtils.ps1 b/scripts/VcpkgPowershellUtils.ps1 index 676ee5c03..63069f44d 100644 --- a/scripts/VcpkgPowershellUtils.ps1 +++ b/scripts/VcpkgPowershellUtils.ps1 @@ -103,22 +103,25 @@ function vcpkgGetSHA512([Parameter(Mandatory=$true)][string]$filePath) return $hash.ToLower() } -function vcpkgCheckEqualFileHash( [Parameter(Mandatory=$true)][string]$filePath, +function vcpkgCheckEqualFileHash( [Parameter(Mandatory=$true)][string]$url, + [Parameter(Mandatory=$true)][string]$filePath, [Parameter(Mandatory=$true)][string]$expectedHash, [Parameter(Mandatory=$true)][string]$actualHash) { if ($expectedHash -ne $actualHash) { Write-Host ("`nFile does not have expected hash:`n" + + " url: [ $url ]`n" + " File path: [ $filePath ]`n" + " Expected hash: [ $expectedHash ]`n" + " Actual hash: [ $actualHash ]`n") - throw "Invalid Hash for file $filePath" + throw } } function vcpkgDownloadFile( [Parameter(Mandatory=$true)][string]$url, - [Parameter(Mandatory=$true)][string]$downloadPath) + [Parameter(Mandatory=$true)][string]$downloadPath, + [Parameter(Mandatory=$true)][string]$sha512) { if (Test-Path $downloadPath) { @@ -152,12 +155,17 @@ function vcpkgDownloadFile( [Parameter(Mandatory=$true)][string]$url, } $wc.DownloadFile($url, $downloadPartPath) + + $actualHash = vcpkgGetSHA512 $downloadPartPath + vcpkgCheckEqualFileHash -url $url -filePath $downloadPath -expectedHash $sha512 -actualHash $actualHash + Move-Item -Path $downloadPartPath -Destination $downloadPath } function vcpkgDownloadFileWithAria2( [Parameter(Mandatory=$true)][string]$aria2exe, [Parameter(Mandatory=$true)][string]$url, - [Parameter(Mandatory=$true)][string]$downloadPath) + [Parameter(Mandatory=$true)][string]$downloadPath, + [Parameter(Mandatory=$true)][string]$sha512) { if (Test-Path $downloadPath) { @@ -178,6 +186,9 @@ function vcpkgDownloadFileWithAria2( [Parameter(Mandatory=$true)][string]$ari throw } + $actualHash = vcpkgGetSHA512 $downloadPartPath + vcpkgCheckEqualFileHash -url $url -filePath $downloadPath -expectedHash $sha512 -actualHash $actualHash + Move-Item -Path $downloadPartPath -Destination $downloadPath } |
