diff options
| author | Alexander Karatarakis <alkarata@microsoft.com> | 2017-02-02 16:00:30 -0800 |
|---|---|---|
| committer | Alexander Karatarakis <alkarata@microsoft.com> | 2017-02-02 16:00:30 -0800 |
| commit | ce9927f7327bc71ade246108a7d984deda6293fd (patch) | |
| tree | 3247c24273a9c45ef2749832a3c5e3b5e4f5b278 /scripts/fetchDependency.ps1 | |
| parent | b2b2c9136918ed3ef85961c5c2885b9562d07d1d (diff) | |
| download | vcpkg-ce9927f7327bc71ade246108a7d984deda6293fd.tar.gz vcpkg-ce9927f7327bc71ade246108a7d984deda6293fd.zip | |
Improve error handling if BITS transfer fails
Diffstat (limited to 'scripts/fetchDependency.ps1')
| -rw-r--r-- | scripts/fetchDependency.ps1 | 20 |
1 files changed, 13 insertions, 7 deletions
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) } } |
