mirror of
https://github.com/dockur/windows.git
synced 2026-07-27 21:42:36 +07:00
feat: Use retry function from base image (#1915)
This commit is contained in:
+24
-53
@@ -758,10 +758,10 @@ downloadFile() {
|
||||
local sum="$3"
|
||||
local size="$4"
|
||||
local desc="$6"
|
||||
local console_msg="$msg"
|
||||
local connections="${7:-1}"
|
||||
local msg="Downloading $desc"
|
||||
local total total_gb domain dots
|
||||
local console_msg="$msg"
|
||||
|
||||
domain=$(echo "$url" | awk -F/ '{print $3}')
|
||||
dots=$(echo "$domain" | tr -cd '.' | wc -c)
|
||||
@@ -773,16 +773,19 @@ downloadFile() {
|
||||
|
||||
info "$console_msg..."
|
||||
|
||||
if ! downloadToFile \
|
||||
if downloadToFile \
|
||||
"$url" \
|
||||
"$iso" \
|
||||
"$msg" \
|
||||
"${size:-0}" \
|
||||
"$connections" \
|
||||
"Y"; then
|
||||
return 1
|
||||
return 0
|
||||
fi
|
||||
|
||||
local rc=$?
|
||||
(( rc != 0 )) && return "$rc"
|
||||
|
||||
if ! total=$(stat -c%s -- "$iso"); then
|
||||
error "Failed to determine downloaded file size: $iso"
|
||||
return 1
|
||||
@@ -791,11 +794,17 @@ downloadFile() {
|
||||
total_gb=$(formatBytes "$total") || return 1
|
||||
|
||||
if (( total < 100000000 )); then
|
||||
|
||||
error "Invalid download link: $url (is only $total_gb ?). Please report this at $SUPPORT/issues"
|
||||
|
||||
if ! rm -f -- "$iso" "$iso.aria2"; then
|
||||
warn "failed to remove invalid download \"$iso\"!"
|
||||
fi
|
||||
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Status 2 means the download completed but failed validation.
|
||||
# Status 2 means the download completed but failed deterministic validation.
|
||||
verifyFile "$iso" "$size" "$total" "$sum" || return 2
|
||||
|
||||
# Extract the .iso from the compressed archive if needed.
|
||||
@@ -813,56 +822,18 @@ tryDownload() {
|
||||
local lang="$5"
|
||||
local desc="$6"
|
||||
local seconds="$7"
|
||||
local connections="${CONNECTIONS:-1}"
|
||||
local rc=0
|
||||
|
||||
# Always start without stale partial or aria control files.
|
||||
rm -f -- "$iso" "$iso.aria2"
|
||||
|
||||
if downloadFile \
|
||||
"$iso" \
|
||||
"$url" \
|
||||
"$sum" \
|
||||
"$size" \
|
||||
"$lang" \
|
||||
"$desc" \
|
||||
"$connections"; then
|
||||
return 0
|
||||
else
|
||||
rc=$?
|
||||
fi
|
||||
|
||||
# Do not download the same file again when its contents failed validation.
|
||||
if (( rc == 2 )); then
|
||||
rm -f -- "$iso" "$iso.aria2"
|
||||
return 1
|
||||
fi
|
||||
|
||||
delay "$seconds"
|
||||
|
||||
# A multi-connection partial file can contain non-sequential
|
||||
# ranges and cannot safely be resumed by Wget.
|
||||
if (( connections > 1 )); then
|
||||
if ! rm -f -- "$iso" "$iso.aria2"; then
|
||||
error "Failed to remove partial download \"$iso\"!"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Retry using the original single-connection Wget behavior.
|
||||
if downloadFile \
|
||||
"$iso" \
|
||||
"$url" \
|
||||
"$sum" \
|
||||
"$size" \
|
||||
"$lang" \
|
||||
"$desc" \
|
||||
"1"; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
rm -f -- "$iso" "$iso.aria2"
|
||||
return 1
|
||||
downloadRetry \
|
||||
"$iso" \
|
||||
"${CONNECTIONS:-1}" \
|
||||
"$seconds" \
|
||||
"$desc" \
|
||||
"$iso" \
|
||||
"$url" \
|
||||
"$sum" \
|
||||
"$size" \
|
||||
"$lang" \
|
||||
"$desc"
|
||||
}
|
||||
|
||||
fallbackEnglish() {
|
||||
|
||||
Reference in New Issue
Block a user