[ps1] Verify hash for already present files. Dont check for path twice

This commit is contained in:
Alexander Karatarakis 2018-04-06 15:22:50 -07:00
parent b87aeb77de
commit d5a1e10541
2 changed files with 8 additions and 19 deletions

View File

@ -105,9 +105,9 @@ function vcpkgGetSHA512([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)
[Parameter(Mandatory=$true)][string]$expectedHash)
{
$actualHash = vcpkgGetSHA512 $filePath
if ($expectedHash -ne $actualHash)
{
Write-Host ("`nFile does not have expected hash:`n" +
@ -123,11 +123,6 @@ function vcpkgDownloadFile( [Parameter(Mandatory=$true)][string]$url,
[Parameter(Mandatory=$true)][string]$downloadPath,
[Parameter(Mandatory=$true)][string]$sha512)
{
if (Test-Path $downloadPath)
{
return
}
if ($url -match "github")
{
if ([System.Enum]::IsDefined([Net.SecurityProtocolType], "Tls12"))
@ -155,10 +150,7 @@ function vcpkgDownloadFile( [Parameter(Mandatory=$true)][string]$url,
}
$wc.DownloadFile($url, $downloadPartPath)
$actualHash = vcpkgGetSHA512 $downloadPartPath
vcpkgCheckEqualFileHash -url $url -filePath $downloadPath -expectedHash $sha512 -actualHash $actualHash
vcpkgCheckEqualFileHash -url $url -filePath $downloadPartPath -expectedHash $sha512
Move-Item -Path $downloadPartPath -Destination $downloadPath
}
@ -167,11 +159,6 @@ function vcpkgDownloadFileWithAria2( [Parameter(Mandatory=$true)][string]$ari
[Parameter(Mandatory=$true)][string]$downloadPath,
[Parameter(Mandatory=$true)][string]$sha512)
{
if (Test-Path $downloadPath)
{
return
}
vcpkgCreateParentDirectoryIfNotExists $downloadPath
$downloadPartPath = "$downloadPath.part"
vcpkgRemoveItem $downloadPartPath
@ -186,9 +173,7 @@ function vcpkgDownloadFileWithAria2( [Parameter(Mandatory=$true)][string]$ari
throw
}
$actualHash = vcpkgGetSHA512 $downloadPartPath
vcpkgCheckEqualFileHash -url $url -filePath $downloadPath -expectedHash $sha512 -actualHash $actualHash
vcpkgCheckEqualFileHash -url $url -filePath $downloadPartPath -expectedHash $sha512
Move-Item -Path $downloadPartPath -Destination $downloadPath
}

View File

@ -61,6 +61,10 @@ function fetchToolInternal([Parameter(Mandatory=$true)][string]$tool)
Write-Host "Downloading $tool... done."
}
else
{
vcpkgCheckEqualFileHash -url $url -filePath $downloadPath -expectedHash $toolData.sha512
}
if ($isArchive)
{