Skip to content
This repository was archived by the owner on Apr 20, 2023. It is now read-only.

Commit 6222e66

Browse files
author
John Beisner
committed
Changes per code review - stronger download failure logic.
1 parent 1fe96fd commit 6222e66

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

scripts/obtain/dotnet-install.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ function Get-Download-Links([string]$AzureFeed, [string]$Channel, [string]$Speci
217217
$ret = @()
218218

219219
if ($SharedRuntime) {
220-
$PayloadURL = "$AzureFeed/Runtime/$SpecificVersion/dotnet-sharedframework-win-$CLIArchitecture.$SpecificVersion.zip"
220+
$PayloadURL = "$AzureFeed/Runtime/$SpecificVersion/dotnet-win-$CLIArchitecture.$SpecificVersion.zip"
221221
}
222222
else {
223223
$PayloadURL = "$AzureFeed/Sdk/$SpecificVersion/dotnet-dev-win-$CLIArchitecture.$SpecificVersion.zip"

scripts/obtain/dotnet-install.sh

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,12 @@ get_normalized_architecture_from_architecture() {
277277
return 0
278278
;;
279279
x86)
280-
say_err "Architecture ``x86`` currently not supported"
280+
say_err "Architecture \`x86\` currently not supported"
281281
return 1
282282
;;
283283
esac
284284

285-
say_err "Architecture ``$architecture`` not supported. If you think this is a bug, please report it at https://github.com/dotnet/cli/issues"
285+
say_err "Architecture \`$architecture\` not supported. If you think this is a bug, please report it at https://github.com/dotnet/cli/issues"
286286
return 1
287287
}
288288

@@ -399,7 +399,7 @@ construct_download_link() {
399399

400400
local download_link=null
401401
if [ "$shared_runtime" = true ]; then
402-
download_link="$azure_feed/Runtime/$specific_version/dotnet-sharedframework-$osname-$normalized_architecture.$specific_version.tar.gz"
402+
download_link="$azure_feed/Runtime/$specific_version/dotnet-$osname-$normalized_architecture.$specific_version.tar.gz"
403403
else
404404
download_link="$azure_feed/Sdk/$specific_version/dotnet-dev-$osname-$normalized_architecture.$specific_version.tar.gz"
405405
fi
@@ -426,7 +426,7 @@ construct_alt_download_link() {
426426

427427
local alt_download_link=null
428428
if [ "$shared_runtime" = true ]; then
429-
alt_download_link="$azure_feed/Runtime/$specific_version/dotnet-sharedframework-$distro_specific_osname-$normalized_architecture.$specific_version.tar.gz"
429+
alt_download_link="$azure_feed/Runtime/$specific_version/dotnet-$distro_specific_osname-$normalized_architecture.$specific_version.tar.gz"
430430
else
431431
alt_download_link="$azure_feed/Sdk/$specific_version/dotnet-dev-$distro_specific_osname-$normalized_architecture.$specific_version.tar.gz"
432432
fi
@@ -554,11 +554,14 @@ download() {
554554
downloadcurl $remote_path $out_path || failed=true
555555
elif machine_has "wget"; then
556556
downloadwget $remote_path $out_path || failed=true
557+
else
558+
failed=true
557559
fi
558560
if [ "$failed" = true ]; then
559-
say_err "Download failed"
561+
say_verbose "Download failed: $remote_path"
560562
return 1
561563
fi
564+
return 0
562565
}
563566

564567
downloadcurl() {
@@ -572,6 +575,11 @@ downloadcurl() {
572575
else
573576
curl --retry 10 -sSL --create-dirs -o $out_path $remote_path || failed=true
574577
fi
578+
if [ "$failed" = true ]; then
579+
say_verbose "Curl download failed"
580+
return 1
581+
fi
582+
return 0
575583
}
576584

577585
downloadwget() {
@@ -585,6 +593,11 @@ downloadwget() {
585593
else
586594
wget -v --tries 10 -O $out_path $remote_path || failed=true
587595
fi
596+
if [ "$failed" = true ]; then
597+
say_verbose "Wget download failed"
598+
return 1
599+
fi
600+
return 0
588601
}
589602

590603
calculate_vars() {
@@ -614,7 +627,8 @@ calculate_vars() {
614627

615628
install_dotnet() {
616629
eval $invocation
617-
630+
local download_failed=false
631+
618632
if is_dotnet_package_installed $install_root "sdk" $specific_version; then
619633
say ".NET SDK version $specific_version is already installed."
620634
return 0
@@ -623,19 +637,17 @@ install_dotnet() {
623637
mkdir -p $install_root
624638
zip_path=$(mktemp $temporary_file_template)
625639
say_verbose "Zip path: $zip_path"
626-
640+
627641
say "Downloading $download_link"
628-
download "$download_link" $zip_path
629-
say_verbose "Downloaded file exists and readable? $(if [ -r $zip_path ]; then echo "yes"; else echo "no"; fi)"
642+
download "$download_link" $zip_path || download_failed=true
630643

631644
# if the download fails, download the alt_download_link [Linux only]
632-
if [ "$(uname)" = "Linux" ] && [ ! -r $zip_path ]; then
645+
if [ "$(uname)" = "Linux" ] && [ "$download_failed" = true ]; then
633646
say "Cannot download $download_link"
634-
alt_zip_path=$(mktemp $temporary_file_template)
635-
say_verbose "Alternate zip path: $alt_zip_path"
647+
zip_path=$(mktemp $temporary_file_template)
648+
say_verbose "Alternate zip path: $zip_path"
636649
say "Downloading alternate: $alt_download_link"
637-
download "$alt_download_link" $alt_zip_path
638-
say_verbose "Downloaded alternate file exists and readable? $(if [ -r $alt_zip_path ]; then echo "yes"; else echo "no"; fi)"
650+
download "$alt_download_link" $zip_path
639651
fi
640652

641653
say "Extracting zip"
@@ -719,7 +731,7 @@ do
719731
echo "Options:"
720732
echo " -c,--channel <CHANNEL> Download from the CHANNEL specified (default: $channel)."
721733
echo " -Channel"
722-
echo " -v,--version <VERSION> Use specific version, ``latest``. Defaults to ``latest``."
734+
echo " -v,--version <VERSION> Use specific version, or \`latest\`. Defaults to \`latest\`."
723735
echo " -Version"
724736
echo " -i,--install-dir <DIR> Install under specified location (see Install Location below)"
725737
echo " -InstallDir"
@@ -769,7 +781,7 @@ install_dotnet
769781

770782
bin_path=$(get_absolute_path $(combine_paths $install_root $bin_folder_relative_path))
771783
if [ "$no_path" = false ]; then
772-
say "Adding to current process PATH: ``$bin_path``. Note: This change will be visible only when sourcing script."
784+
say "Adding to current process PATH: \`$bin_path\`. Note: This change will be visible only when sourcing script."
773785
export PATH=$bin_path:$PATH
774786
else
775787
say "Binaries of dotnet can be found in $bin_path"

0 commit comments

Comments
 (0)