Improve error handling if BITS transfer fails

This commit is contained in:
Alexander Karatarakis 2017-02-02 16:00:30 -08:00
parent b2b2c91369
commit ce9927f732

View File

@ -70,17 +70,23 @@ function SelectProgram([Parameter(Mandatory=$true)][string]$Dependency)
if ($Dependency -ne "git") # git fails with BITS
{
Start-BitsTransfer -Source $url -Destination $downloadPath -ErrorAction SilentlyContinue
try {
Start-BitsTransfer -Source $url -Destination $downloadPath -ErrorAction Stop
}
else
catch [System.Exception] {
# If BITS fails for any reason, delete any potentially partially downloaded files and continue
if (Test-Path $downloadPath)
{
Remove-Item $downloadPath
}
}
}
if (!(Test-Path $downloadPath))
{
Write-Host("Downloading $Dependency...")
(New-Object System.Net.WebClient).DownloadFile($url, $downloadPath)
}
}
}
# Enums (without resorting to C#) are only available on powershell 5+.
$ExtractionType_NO_EXTRACTION_REQUIRED = 0