mirror of https://github.com/microsoft/vcpkg.git
[fetchTool.ps1] Move downloaded file in place after hash check
This commit is contained in:
parent
5b78dfaf68
commit
3a9be92f7e
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -51,21 +51,17 @@ function fetchToolInternal([Parameter(Mandatory=$true)][string]$tool)
|
|||
# Download aria2 with .NET. aria2 will be used to download everything else.
|
||||
if ($tool -eq "aria2")
|
||||
{
|
||||
vcpkgDownloadFile $url $downloadPath
|
||||
vcpkgDownloadFile $url $downloadPath $toolData.sha512
|
||||
}
|
||||
else
|
||||
{
|
||||
$aria2exe = fetchToolInternal "aria2"
|
||||
vcpkgDownloadFileWithAria2 $aria2exe $url $downloadPath
|
||||
vcpkgDownloadFileWithAria2 $aria2exe $url $downloadPath $toolData.sha512
|
||||
}
|
||||
|
||||
Write-Host "Downloading $tool... done."
|
||||
}
|
||||
|
||||
$expectedDownloadedFileHash = $toolData.sha512
|
||||
$downloadedFileHash = vcpkgGetSHA512 $downloadPath
|
||||
vcpkgCheckEqualFileHash -filePath $downloadPath -expectedHash $expectedDownloadedFileHash -actualHash $downloadedFileHash
|
||||
|
||||
if ($isArchive)
|
||||
{
|
||||
Write-Host "Extracting $tool..."
|
||||
|
|
|
|||
Loading…
Reference in New Issue