|
@@ -22,7 +22,7 @@ export BR_BACKEND_DL_GETOPTS=":hc:d:o:n:N:H:lru:qf:e"
|
|
main() {
|
|
main() {
|
|
local OPT OPTARG
|
|
local OPT OPTARG
|
|
local backend output large_file recurse quiet rc
|
|
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
|
|
# Parse our options; anything after '--' is for the backend
|
|
while getopts ":c:d:D:o:n:N:H:lrf:u:qp:" OPT; do
|
|
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.
|
|
# If we can neither link nor copy, fallback to doing a download.
|
|
# NOTE! This is not atomic, is subject to TOCTTOU, but the whole
|
|
# NOTE! This is not atomic, is subject to TOCTTOU, but the whole
|
|
# dl-wrapper runs under an flock, so we're safe.
|
|
# 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
|
|
if [ ! -e "${output}" -a -e "${old_dl_dir}/${filename}" ]; then
|
|
ln "${old_dl_dir}/${filename}" "${output}" || \
|
|
ln "${old_dl_dir}/${filename}" "${output}" || \
|
|
cp "${old_dl_dir}/${filename}" "${output}" || \
|
|
cp "${old_dl_dir}/${filename}" "${output}" || \
|
|
@@ -112,6 +113,12 @@ main() {
|
|
tmpd="$(mktemp -d "${BUILD_DIR}/.${output##*/}.XXXXXX")"
|
|
tmpd="$(mktemp -d "${BUILD_DIR}/.${output##*/}.XXXXXX")"
|
|
tmpf="${tmpd}/output"
|
|
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
|
|
# 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.
|
|
# 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.
|
|
# 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
|
|
# the next URI until it succeeds. Once out of URI to try, we need to
|
|
# cleanup and exit.
|
|
# cleanup and exit.
|
|
if ! "${OLDPWD}/support/download/${backend}" \
|
|
if ! "${OLDPWD}/support/download/${backend}" \
|
|
- $([ -n "${urlencode}" ] && printf %s '-e') \
|
|
|
|
-c "${cset}" \
|
|
-c "${cset}" \
|
|
-d "${dl_dir}" \
|
|
-d "${dl_dir}" \
|
|
-n "${raw_base_name}" \
|
|
-n "${raw_base_name}" \
|
|
@@ -130,7 +136,9 @@ main() {
|
|
-f "${filename}" \
|
|
-f "${filename}" \
|
|
-u "${uri}" \
|
|
-u "${uri}" \
|
|
-o "${tmpf}" \
|
|
-o "${tmpf}" \
|
|
- ${quiet} ${large_file} ${recurse} -- "${@}"
|
|
|
|
|
|
+ "${backend_opts[@]}" \
|
|
|
|
+ -- \
|
|
|
|
+ "${@}"
|
|
then
|
|
then
|
|
# cd back to keep path coherence
|
|
# cd back to keep path coherence
|
|
cd "${OLDPWD}"
|
|
cd "${OLDPWD}"
|
|
@@ -194,8 +202,8 @@ main() {
|
|
# Some backends (cp and scp) may create executable files, so we need to
|
|
# Some backends (cp and scp) may create executable files, so we need to
|
|
# carry the executable bit if needed.
|
|
# carry the executable bit if needed.
|
|
[ -x "${tmpf}" ] && new_mode=755 || new_mode=644
|
|
[ -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
|
|
# We must *not* unlink tmp_output, otherwise there is a small window
|
|
# during which another download process may create the same tmp_output
|
|
# 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}" "${@}"; }
|
|
trace() { local msg="${1}"; shift; printf "%s: ${msg}" "${my_name}" "${@}"; }
|
|
warn() { trace "${@}" >&2; }
|
|
warn() { trace "${@}" >&2; }
|
|
-errorN() { local ret="${1}"; shift; warn "${@}"; exit ${ret}; }
|
|
|
|
|
|
+errorN() { local ret="${1}"; shift; warn "${@}"; exit "${ret}"; }
|
|
error() { errorN 1 "${@}"; }
|
|
error() { errorN 1 "${@}"; }
|
|
|
|
|
|
my_name="${0##*/}"
|
|
my_name="${0##*/}"
|