fix(core): unhandled curl fail (#4159)

This commit is contained in:
jusito 2023-04-01 23:37:10 +02:00 committed by GitHub
parent 4c717c5b94
commit 75852abb42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -383,17 +383,21 @@ fn_fetch_file() {
fi
# Trap will remove part downloaded files if canceled.
trap fn_fetch_trap INT
# Larger files show a progress bar.
if [ "${local_filename##*.}" == "bz2" ] || [ "${local_filename##*.}" == "gz" ] || [ "${local_filename##*.}" == "zip" ] || [ "${local_filename##*.}" == "jar" ] || [ "${local_filename##*.}" == "xz" ]; then
echo -e "downloading ${local_filename}..."
fn_sleep_time
curlcmd=$(curl --connect-timeout 10 --progress-bar --fail -L -o "${local_filedir}/${local_filename}" "${fileurl}")
local exitcode=$?
curlcmd=(curl --connect-timeout 10 --fail -L -o "${local_filedir}/${local_filename}" --retry 2)
# if is large file show progress, else be silent
local exitcode=""
large_files=("bz2" "gz" "zip" "jar" "xz")
if grep -qE "(^|\s)${local_filename##*.}(\s|$)" <<< "${large_files[@]}"; then
echo -en "downloading ${local_filename}..."
fn_sleep_time
echo -en "\033[1K"
"${curlcmd[@]}" --progress-bar "${fileurl}" 2>&1
exitcode="$?"
else
curlcmd=$(curl --connect-timeout 10 -s --fail -L -o "${local_filedir}/${local_filename}" "${fileurl}")
local exitcode=$?
echo -en "fetching ${fileurl_name} ${local_filename}...\c"
"${curlcmd[@]}" --silent --show-error "${fileurl}" 2>&1
exitcode="$?"
fi
# Download will fail if downloads a html file.