diff options
| author | Alexander Karatarakis <alkarata@microsoft.com> | 2017-11-03 15:48:21 -0700 |
|---|---|---|
| committer | Alexander Karatarakis <alkarata@microsoft.com> | 2017-11-03 16:14:13 -0700 |
| commit | 82ce87cfd0854907a270ef2f8de80670bd8428b3 (patch) | |
| tree | 27f6262ac82bea02c80b9a0ad67c41aac38e00b4 /scripts/fetchDependency.ps1 | |
| parent | 7af697e6e8c257546e44b8788588c1f1ef52fafd (diff) | |
| download | vcpkg-82ce87cfd0854907a270ef2f8de80670bd8428b3.tar.gz vcpkg-82ce87cfd0854907a270ef2f8de80670bd8428b3.zip | |
Use download-at-temp-and-rename pattern in powershell too
Diffstat (limited to 'scripts/fetchDependency.ps1')
| -rw-r--r-- | scripts/fetchDependency.ps1 | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/scripts/fetchDependency.ps1 b/scripts/fetchDependency.ps1 index 4ef3a1f17..9d3f76386 100644 --- a/scripts/fetchDependency.ps1 +++ b/scripts/fetchDependency.ps1 @@ -65,6 +65,18 @@ function SelectProgram([Parameter(Mandatory=$true)][string]$Dependency) New-Item -ItemType directory -Path $downloadDir | Out-Null } + $downloadsTemp = "$downloadDir/temp" + if (Test-Path $downloadsTemp) # Delete temp dir if it exists + { + Remove-Item $downloadsTemp -Recurse -Force + } + if (!(Test-Path $downloadsTemp)) # Recreate temp dir. It may still be there the dir was in use + { + New-Item -ItemType directory -Path $downloadsTemp | Out-Null + } + + $tempDownloadName = "$downloadsTemp/$Dependency-$downloadVersion.temp" + $WC = New-Object System.Net.WebClient $ProxyAuth = !$WC.Proxy.IsBypassed($url) @@ -79,15 +91,16 @@ function SelectProgram([Parameter(Mandatory=$true)][string]$Dependency) $PSDefaultParameterValues.Add("Start-BitsTransfer:ProxyAuthentication","Basic") $PSDefaultParameterValues.Add("Start-BitsTransfer:ProxyCredential", $ProxyCred) } - Start-BitsTransfer -Source $url -Destination $downloadPath -ErrorAction Stop + Start-BitsTransfer -Source $url -Destination $tempDownloadName -ErrorAction Stop + Move-Item -Path $tempDownloadName -Destination $downloadPath return } catch [System.Exception] { # If BITS fails for any reason, delete any potentially partially downloaded files and continue - if (Test-Path $downloadPath) + if (Test-Path $tempDownloadName) { - Remove-Item $downloadPath + Remove-Item $tempDownloadName } } } @@ -98,7 +111,8 @@ function SelectProgram([Parameter(Mandatory=$true)][string]$Dependency) } Write-Verbose("Downloading $Dependency...") - $WC.DownloadFile($url, $downloadPath) + $WC.DownloadFile($url, $tempDownloadName) + Move-Item -Path $tempDownloadName -Destination $downloadPath } # Enums (without resorting to C#) are only available on powershell 5+. |
