mirror of
https://github.com/dockur/windows.git
synced 2026-08-03 20:47:12 +01: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 sum="$3"
|
||||||
local size="$4"
|
local size="$4"
|
||||||
local desc="$6"
|
local desc="$6"
|
||||||
local console_msg="$msg"
|
|
||||||
local connections="${7:-1}"
|
local connections="${7:-1}"
|
||||||
local msg="Downloading $desc"
|
local msg="Downloading $desc"
|
||||||
local total total_gb domain dots
|
local total total_gb domain dots
|
||||||
|
local console_msg="$msg"
|
||||||
|
|
||||||
domain=$(echo "$url" | awk -F/ '{print $3}')
|
domain=$(echo "$url" | awk -F/ '{print $3}')
|
||||||
dots=$(echo "$domain" | tr -cd '.' | wc -c)
|
dots=$(echo "$domain" | tr -cd '.' | wc -c)
|
||||||
@@ -773,16 +773,19 @@ downloadFile() {
|
|||||||
|
|
||||||
info "$console_msg..."
|
info "$console_msg..."
|
||||||
|
|
||||||
if ! downloadToFile \
|
if downloadToFile \
|
||||||
"$url" \
|
"$url" \
|
||||||
"$iso" \
|
"$iso" \
|
||||||
"$msg" \
|
"$msg" \
|
||||||
"${size:-0}" \
|
"${size:-0}" \
|
||||||
"$connections" \
|
"$connections" \
|
||||||
"Y"; then
|
"Y"; then
|
||||||
return 1
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
local rc=$?
|
||||||
|
(( rc != 0 )) && return "$rc"
|
||||||
|
|
||||||
if ! total=$(stat -c%s -- "$iso"); then
|
if ! total=$(stat -c%s -- "$iso"); then
|
||||||
error "Failed to determine downloaded file size: $iso"
|
error "Failed to determine downloaded file size: $iso"
|
||||||
return 1
|
return 1
|
||||||
@@ -791,11 +794,17 @@ downloadFile() {
|
|||||||
total_gb=$(formatBytes "$total") || return 1
|
total_gb=$(formatBytes "$total") || return 1
|
||||||
|
|
||||||
if (( total < 100000000 )); then
|
if (( total < 100000000 )); then
|
||||||
|
|
||||||
error "Invalid download link: $url (is only $total_gb ?). Please report this at $SUPPORT/issues"
|
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
|
return 1
|
||||||
fi
|
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
|
verifyFile "$iso" "$size" "$total" "$sum" || return 2
|
||||||
|
|
||||||
# Extract the .iso from the compressed archive if needed.
|
# Extract the .iso from the compressed archive if needed.
|
||||||
@@ -813,56 +822,18 @@ tryDownload() {
|
|||||||
local lang="$5"
|
local lang="$5"
|
||||||
local desc="$6"
|
local desc="$6"
|
||||||
local seconds="$7"
|
local seconds="$7"
|
||||||
local connections="${CONNECTIONS:-1}"
|
|
||||||
local rc=0
|
|
||||||
|
|
||||||
# Always start without stale partial or aria control files.
|
downloadRetry \
|
||||||
rm -f -- "$iso" "$iso.aria2"
|
"$iso" \
|
||||||
|
"${CONNECTIONS:-1}" \
|
||||||
if downloadFile \
|
"$seconds" \
|
||||||
"$iso" \
|
"$desc" \
|
||||||
"$url" \
|
"$iso" \
|
||||||
"$sum" \
|
"$url" \
|
||||||
"$size" \
|
"$sum" \
|
||||||
"$lang" \
|
"$size" \
|
||||||
"$desc" \
|
"$lang" \
|
||||||
"$connections"; then
|
"$desc"
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fallbackEnglish() {
|
fallbackEnglish() {
|
||||||
|
|||||||
Reference in New Issue
Block a user