summaryrefslogtreecommitdiff
path: root/dotnet-download.ps1
diff options
context:
space:
mode:
authorLuis G <lggomez@users.noreply.github.com>2017-04-01 06:00:12 -0300
committerJan Vorlicek <janvorli@microsoft.com>2017-04-01 11:00:12 +0200
commit8cfb891b135a24c6436647ec4ca9aa2a07eb9da5 (patch)
tree4b339400294a3cc3779200f46641714150110396 /dotnet-download.ps1
parenta7ab04cfb152f133d130948709dd5ac4f1494a19 (diff)
downloadcoreclr-8cfb891b135a24c6436647ec4ca9aa2a07eb9da5.tar.gz
coreclr-8cfb891b135a24c6436647ec4ca9aa2a07eb9da5.tar.bz2
coreclr-8cfb891b135a24c6436647ec4ca9aa2a07eb9da5.zip
Refactor dotnet download code in init-tools.cmd (#10527)
* Refactor dotnet download code in init-tools.cmd This addresses the improvements proposed in issue #10526. Includes the init-tools.cmd script refactor and a new script called dotnet-download.ps1 which includes the extracted code and logic * Code review feedback changes * Fix spacing
Diffstat (limited to 'dotnet-download.ps1')
-rw-r--r--dotnet-download.ps137
1 files changed, 37 insertions, 0 deletions
diff --git a/dotnet-download.ps1 b/dotnet-download.ps1
new file mode 100644
index 0000000000..ef5808f2a2
--- /dev/null
+++ b/dotnet-download.ps1
@@ -0,0 +1,37 @@
+param(
+ [parameter(Mandatory=$true)]$DotnetRemotePath,
+ [parameter(Mandatory=$true)]$DotnetLocalPath,
+ [parameter(Mandatory=$true)]$DotnetPath
+)
+
+$retryCount = 0
+$success = $false
+
+do {
+ try {
+ Write-Output "Downloading from $DotnetRemotePath"
+ (New-Object Net.WebClient).DownloadFile($DotnetRemotePath, $DotnetLocalPath)
+ $success = $true
+ } catch {
+ if ($retryCount -ge 6) {
+ Write-Output "Maximum of 5 retries exceeded. Aborting"
+ throw
+ }
+ else {
+ $retryCount++
+ $retryTime = 5 * $retryCount
+ Write-Output "Download failed. Retrying in $retryTime seconds"
+ Start-Sleep -Seconds (5 * $retryCount)
+ }
+ }
+} while ($success -eq $false)
+
+Write-Output "Download finished"
+Add-Type -Assembly 'System.IO.Compression.FileSystem' -ErrorVariable AddTypeErrors
+
+if ($AddTypeErrors.Count -eq 0) {
+ [System.IO.Compression.ZipFile]::ExtractToDirectory($DotnetLocalPath, $DotnetPath)
+}
+else {
+ (New-Object -com shell.application).namespace($DotnetPath).CopyHere((new-object -com shell.application).namespace($DotnetLocalPath).Items(), 16)
+} \ No newline at end of file