Unverified Commit ec8f54b8 authored by Andrey Butirsky's avatar Andrey Butirsky Committed by GitHub
Browse files

feat: Continue partially downloaded file (#821)

Added retry logic for downloadFile function
parent 66413d4c
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -111,7 +111,6 @@ downloadFile() {
  local msg rc total size progress

  local dest="$STORAGE/$base"
  rm -f "$dest"

  # Check if running with interactive TTY or redirected to docker log
  if [ -t 1 ]; then
@@ -132,7 +131,7 @@ downloadFile() {

  /run/progress.sh "$dest" "0" "$msg ([P])..." &

  { wget "$url" -O "$dest" -q --timeout=30 --no-http-keep-alive --show-progress "$progress"; rc=$?; } || :
  { wget "$url" -O "$dest" --continue -q --timeout=30 --no-http-keep-alive --show-progress "$progress"; rc=$?; } || :

  fKill "progress.sh"

@@ -343,9 +342,19 @@ find "$STORAGE" -maxdepth 1 -type f \( -iname 'data.*' -or -iname 'qemu.*' \) -d

base=$(getBase "$BOOT")

rm -f "$STORAGE/$base"

if ! downloadFile "$BOOT" "$base" "$name"; then
  info "Retrying failed download in 5 seconds..."
  sleep 5
  if ! downloadFile "$BOOT" "$base" "$name"; then
    info "Retrying failed download in 5 seconds..."
    sleep 5  
    if ! downloadFile "$BOOT" "$base" "$name"; then
      rm -f "$STORAGE/$base" && exit 60
    fi
  fi
fi

case "${base,,}" in
  *".gz" | *".gzip" | *".xz" | *".7z" | *".zip" | *".rar" | *".lzma" | *".bz" | *".bz2" )