From e7dc2ccdb085447c9c3c9d94014bd4ca518acc19 Mon Sep 17 00:00:00 2001 From: "Yann E. MORIN" Date: Fri, 7 Jun 2024 19:05:46 +0200 Subject: [PATCH] support/download/dl-wrapper: fix shellcheck errors Signed-off-by: Yann E. MORIN Signed-off-by: Arnout Vandecappelle --- .checkpackageignore | 1 - support/download/dl-wrapper | 20 ++++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/.checkpackageignore b/.checkpackageignore index db28680f40..d36a70c18f 100644 --- a/.checkpackageignore +++ b/.checkpackageignore @@ -1528,7 +1528,6 @@ support/dependencies/check-host-xzcat.sh Shellcheck support/dependencies/dependencies.sh Shellcheck support/download/bzr Shellcheck lib_shellscript.ConsecutiveEmptyLines support/download/cargo-post-process Shellcheck -support/download/dl-wrapper Shellcheck support/download/file Shellcheck support/download/go-post-process Shellcheck support/download/hg Shellcheck diff --git a/support/download/dl-wrapper b/support/download/dl-wrapper index 069b2c1c21..d1ba281f79 100755 --- a/support/download/dl-wrapper +++ b/support/download/dl-wrapper @@ -22,7 +22,7 @@ export BR_BACKEND_DL_GETOPTS=":hc:d:o:n:N:H:lru:qf:e" main() { local OPT OPTARG local backend output large_file recurse quiet rc - local -a uris hfiles + local -a uris hfiles backend_opts # Parse our options; anything after '--' is for the backend while getopts ":c:d:D:o:n:N:H:lrf:u:qp:" OPT; do @@ -58,6 +58,7 @@ main() { # If we can neither link nor copy, fallback to doing a download. # NOTE! This is not atomic, is subject to TOCTTOU, but the whole # dl-wrapper runs under an flock, so we're safe. + # shellcheck disable=SC2166 # -a works in this case if [ ! -e "${output}" -a -e "${old_dl_dir}/${filename}" ]; then ln "${old_dl_dir}/${filename}" "${output}" || \ cp "${old_dl_dir}/${filename}" "${output}" || \ @@ -112,6 +113,12 @@ main() { tmpd="$(mktemp -d "${BUILD_DIR}/.${output##*/}.XXXXXX")" tmpf="${tmpd}/output" + # shellcheck disable=SC2206 # all three are dash-options + backend_opts=( ${quiet} ${large_file} ${recurse} ) + if [ "${urlencode}" ]; then + backend_opts+=( -e ) + fi + # Helpers expect to run in a directory that is *really* trashable, so # they are free to create whatever files and/or sub-dirs they might need. # Doing the 'cd' here rather than in all backends is easier. @@ -122,7 +129,6 @@ main() { # the next URI until it succeeds. Once out of URI to try, we need to # cleanup and exit. if ! "${OLDPWD}/support/download/${backend}" \ - $([ -n "${urlencode}" ] && printf %s '-e') \ -c "${cset}" \ -d "${dl_dir}" \ -n "${raw_base_name}" \ @@ -130,7 +136,9 @@ main() { -f "${filename}" \ -u "${uri}" \ -o "${tmpf}" \ - ${quiet} ${large_file} ${recurse} -- "${@}" + "${backend_opts[@]}" \ + -- \ + "${@}" then # cd back to keep path coherence cd "${OLDPWD}" @@ -194,8 +202,8 @@ main() { # Some backends (cp and scp) may create executable files, so we need to # carry the executable bit if needed. [ -x "${tmpf}" ] && new_mode=755 || new_mode=644 - new_mode=$(printf "%04o" $((0${new_mode} & ~0$(umask)))) - chmod ${new_mode} "${tmp_output}" + new_mode="$(printf "%04o" $((0${new_mode} & ~0$(umask))))" + chmod "${new_mode}" "${tmp_output}" # We must *not* unlink tmp_output, otherwise there is a small window # during which another download process may create the same tmp_output @@ -227,7 +235,7 @@ main() { trace() { local msg="${1}"; shift; printf "%s: ${msg}" "${my_name}" "${@}"; } warn() { trace "${@}" >&2; } -errorN() { local ret="${1}"; shift; warn "${@}"; exit ${ret}; } +errorN() { local ret="${1}"; shift; warn "${@}"; exit "${ret}"; } error() { errorN 1 "${@}"; } my_name="${0##*/}"