From ce9927f7327bc71ade246108a7d984deda6293fd Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 2 Feb 2017 16:00:30 -0800 Subject: Improve error handling if BITS transfer fails --- scripts/fetchDependency.ps1 | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'scripts') diff --git a/scripts/fetchDependency.ps1 b/scripts/fetchDependency.ps1 index b56bf1087..8d31b0edb 100644 --- a/scripts/fetchDependency.ps1 +++ b/scripts/fetchDependency.ps1 @@ -70,15 +70,21 @@ 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 + } + catch [System.Exception] { + # If BITS fails for any reason, delete any potentially partially downloaded files and continue + if (Test-Path $downloadPath) + { + Remove-Item $downloadPath + } + } } - else + if (!(Test-Path $downloadPath)) { - if (!(Test-Path $downloadPath)) - { - Write-Host("Downloading $Dependency...") - (New-Object System.Net.WebClient).DownloadFile($url, $downloadPath) - } + Write-Host("Downloading $Dependency...") + (New-Object System.Net.WebClient).DownloadFile($url, $downloadPath) } } -- cgit v1.2.3