From 4b9dbf8f1a3c99cc36852fc495bdb647cccd7476 Mon Sep 17 00:00:00 2001 From: Kroese Date: Tue, 21 Jul 2026 05:08:18 +0200 Subject: [PATCH] feat: Use retry function from base image (#1915) --- src/mido.sh | 77 +++++++++++++++++------------------------------------ 1 file changed, 24 insertions(+), 53 deletions(-) diff --git a/src/mido.sh b/src/mido.sh index 5f17884a..3f813c66 100644 --- a/src/mido.sh +++ b/src/mido.sh @@ -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() {