From a5cecdd6314b632167f9a4b9e522cbf40609ac6b Mon Sep 17 00:00:00 2001 From: DDSRem <73049927+DDSRem@users.noreply.github.com> Date: Sun, 8 Sep 2024 14:42:01 +0800 Subject: [PATCH] feat(docker): retry if download fails fix https://github.com/jxxghp/MoviePilot/issues/2688 --- update | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/update b/update index 3ba94211..bb39e265 100644 --- a/update +++ b/update @@ -22,15 +22,27 @@ function WARN() { # 下载及解压 function download_and_unzip() { - url="$1" - target_dir="$2" + local retries=0 + local max_retries=3 + local url="$1" + local target_dir="$2" INFO "正在下载 ${url}..." - if curl ${CURL_OPTIONS} "${url}" ${CURL_HEADERS} | busybox unzip -d /tmp - > /dev/null; then - if [ -e /tmp/MoviePilot-* ]; then - mv /tmp/MoviePilot-* /tmp/"${target_dir}" + while [ $retries -lt $max_retries ]; do + if curl ${CURL_OPTIONS} "${url}" ${CURL_HEADERS} | busybox unzip -d /tmp - > /dev/null; then + if [ -e /tmp/MoviePilot-* ]; then + mv /tmp/MoviePilot-* /tmp/"${target_dir}" + fi + break + else + WARN "下载 ${url} 失败,正在进行第 $((retries + 1)) 次重试..." + retries=$((retries + 1)) fi - else + done + if [ $retries -eq $max_retries ]; then + ERROR "下载 ${url} 失败,已达到最大重试次数!" return 1 + else + return 0 fi }