summaryrefslogtreecommitdiffhomepage
path: root/subr.rtl/rtl_fetch.subr
diff options
context:
space:
mode:
Diffstat (limited to 'subr.rtl/rtl_fetch.subr')
-rw-r--r--subr.rtl/rtl_fetch.subr101
1 files changed, 44 insertions, 57 deletions
diff --git a/subr.rtl/rtl_fetch.subr b/subr.rtl/rtl_fetch.subr
index 5f557320..b40d11ba 100644
--- a/subr.rtl/rtl_fetch.subr
+++ b/subr.rtl/rtl_fetch.subr
@@ -2,66 +2,53 @@
# set +o errexit -o noglob -o nounset is assumed.
#
-# N.B. URLs ($1) may contain `?' or '&' characters.
-rtl_fetch_url_wget() {
- local _urls="${1}" _sha256sum_src="${2}" _target_dname="${3}" _target_fname="${4}" _target_name="${5}" _mirrors="${6:-}"\
- _rc=0 _sha256sum_target="" _target_fname_full="" _url="" _url_base="" _urls_count=0 _urls_full="";
+rtl_fetch_clean_dlcache() {
+ local _pfdcd_dlcachedir="${1}" _pfdcd_pkg_name="${2}" \
+ _pfdcd_pkg_fname="${3}" _pfdcd_pkg_urls_git="${4}" \
+ _pfdcd_fname="" _pfdcd_skipfl=0 _pfdcd_url_spec="" \
+ _pfdcd_url_subdir="";
- _urls_full="${_urls}";
- for _url_base in ${_mirrors}; do
- _urls_full="$(rtl_lconcat "${_urls_full}" "${_url_base%/}/${_target_name}/${_target_fname}")";
- done;
- _urls_count="$(rtl_llength "${_urls_full}")";
- for _url in ${_urls_full}; do
- if [ -z "${_target_fname}" ]; then
- _target_fname="$(rtl_basename "${_url}")";
- fi;
- _target_fname_full="${_target_dname}/${_target_fname}";
- (set +o errexit -o noglob -o nounset;
- rtl_flock_acquire 4 || exit 1;
- trap "_rc=\"\${?}\"; rm -f \"${_target_fname_full}.fetching\"; exit \"\${_rc}\";" EXIT;
- if [ -z "${_sha256sum_src}" ]\
- || ! rtl_check_digest_file "${_target_fname_full}" "${_sha256sum_src}" "${_target_fname_full}.fetched"; then
- wget ${DEFAULT_WGET_ARGS} -O "${_target_fname_full}" "${_url}"; _rc="${?}";
- if [ "${_rc}" -ne 0 ]; then
- exit $((${_rc}+2));
- elif [ -n "${_sha256sum_src}" ]\
- && ! rtl_check_digest "${_target_fname_full}" "${_sha256sum_src}"; then
- exit 2;
- else
- printf "%s" "${RTL_CHECK_DIGEST_DIGEST}" > "${_target_fname_full}.fetched"; exit 0;
+ for _pfdcd_fname in \
+ $(cd "${_pfdcd_dlcachedir}/${_pfdcd_pkg_name}" 2>/dev/null &&
+ find -maxdepth 1 -mindepth 1 \
+ ${_pfdcd_pkg_fname:+-not -name "${_pfdcd_pkg_fname}"} \
+ ${_pfdcd_pkg_fname:+-not -name "${_pfdcd_pkg_fname}.fetched"});
+ do
+ _pfdcd_fname="${_pfdcd_fname#./}"; _pfdcd_skipfl=0;
+
+ for _pfdcd_url_spec in ${_pfdcd_pkg_urls_git}; do
+ _pfdcd_url_subdir="${_pfdcd_url_spec%%=*}"; _pfdcd_url_subdir="${_pfdcd_url_subdir##*/}";
+ if [ "${_pfdcd_fname%.git}" = "${_pfdcd_url_subdir}" ]; then
+ _pfdcd_skipfl=1; break;
fi;
- else
- exit 0;
- fi;) 4<>"${_target_fname_full}.fetching"; _rc="${?}"; : $((_urls_count-=1));
- case "${_rc}" in
- 0) break; ;;
- 1) if [ "${_urls_count}" -ge 1 ]; then
- rtl_log_msg "warning" "${MSG_rtl_fetch_lockfail_retryurl}" "${_url}";
- else
- rtl_log_msg "fatal" "${MSG_rtl_fetch_lockfail}" "${_url}";
- rtl_fileop rm "${_target_fname_full}"; break;
- fi; ;;
- 2) if [ "${_urls_count}" -ge 1 ]; then
- rtl_log_msg "warning" "${MSG_rtl_fetch_hashfail_retryurl}" "${_url}" "${_sha256sum_src}";
- else
- if _sha256sum_target="$(sha256sum "${_target_fname_full}" |\
- awk '{print $1}' 2>/dev/null)"; then
- rtl_log_msg "fatal" "${MSG_rtl_fetch_hashfail1}" "${_url}" "${_sha256sum_src}" "${_sha256sum_target}";
- else
- rtl_log_msg "fatal" "${MSG_rtl_fetch_hashfail2}" "${_url}" "${_sha256sum_src}";
- fi;
- rtl_fileop rm "${_target_fname_full}"; break;
- fi; ;;
- *) if [ "${_urls_count}" -ge 1 ]; then
- rtl_log_msg "warning" "${MSG_rtl_fetch_fail_retryurl}" "${_url}" "$((${_rc}-2))";
- else
- rtl_log_msg "fatal" "${MSG_rtl_fetch_fail}" "${_url}" "$((${_rc}-2))";
- rtl_fileop rm "${_target_fname_full}"; break;
- fi; ;;
- esac;
+ done;
+
+ if [ "${_pfdcd_skipfl}" -eq 0 ]; then
+ _pfdcd_fname="${_pfdcd_dlcachedir}/${_pfdcd_pkg_name}/${_pfdcd_fname}";
+ rtl_log_msg "verbose" "${MSG_rtl_fetch_rm_redundant}" "${_pfdcd_fname}" "${_pfdcd_pkg_name}";
+ rtl_fileop rm "${_pfdcd_fname}";
+ fi;
done;
- return "${_rc}";
+
+ return 0;
+};
+
+rtl_fetch_dlcache_subdir() {
+ local _rfds_dlcache_dir="${1}" _rfds_name="${2}" _rfds_pkg_inherit_from="${3}";
+
+ if [ "${_rfds_pkg_inherit_from:+1}" = 1 ]\
+ && ! [ -e "${_rfds_dlcache_dir}/${_rfds_name}" ]\
+ && ! rtl_fileop ln_symbolic "${_rfds_pkg_inherit_from}" "${_rfds_dlcache_dir}/${_rfds_name}";
+ then
+ return 1;
+ elif [ "${_rfds_pkg_inherit_from:+1}" != 1 ]\
+ && ! [ -e "${_rfds_dlcache_dir}/${_rfds_name}" ]\
+ && ! rtl_fileop mkdir "${_rfds_dlcache_dir}/${_rfds_name}";
+ then
+ return 1;
+ else
+ return 0;
+ fi;
};
# vim:filetype=sh