summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--subr/rtl_complex.subr26
-rw-r--r--subr/rtl_fetch.subr39
2 files changed, 46 insertions, 19 deletions
diff --git a/subr/rtl_complex.subr b/subr/rtl_complex.subr
index 63175bed..4894e0f6 100644
--- a/subr/rtl_complex.subr
+++ b/subr/rtl_complex.subr
@@ -2,6 +2,32 @@
# set +o errexit -o noglob -o nounset is assumed.
#
+rtl_check_digest() {
+ local _fname="${1}" _digest_check="${2}" _digest=""; RTL_CHECK_DIGEST_DIGEST="";
+ if ! [ -e "${_fname}" ]; then
+ return 1;
+ else set -- $(sha256sum "${_fname}");
+ RTL_CHECK_DIGEST_DIGEST="${1}";
+ if [ "${RTL_CHECK_DIGEST_DIGEST}" = "${_digest_check}" ]; then
+ return 0;
+ else
+ return 1;
+ fi;
+ fi;
+};
+
+rtl_check_digest_file() {
+ local _fname="${1}" _digest_check="${2}" _digest_fname="${3}" _digest="" RTL_CHECK_DIGEST_DIGEST="";
+ if ! [ -e "${_digest_fname}" ]; then
+ return 1;
+ else _digest="$(cat "${_digest_fname}")";
+ if [ "${_digest}" != "${_digest_check}" ]\
+ || ! rtl_check_digest "${_fname}" "${_digest_check}"; then
+ return 1;
+ fi;
+ fi;
+};
+
rtl_check_path_vars() {
local _vnames="${1}" _rc=0 _vname="" _vname_val=""; _status="";
for _vname in ${_vnames}; do
diff --git a/subr/rtl_fetch.subr b/subr/rtl_fetch.subr
index cf7e3955..350a01e8 100644
--- a/subr/rtl_fetch.subr
+++ b/subr/rtl_fetch.subr
@@ -2,7 +2,7 @@
# set +o errexit -o noglob -o nounset is assumed.
#
-exp_rtl_fetch_url_git() {
+rtlp_fetch_url_git() {
local _tgtdir="${1}" _subdir="${2}" _url="${3}" _branch="${4}" \
_oldpwd="";
(set -o errexit -o noglob -o nounset;
@@ -46,34 +46,35 @@ rtl_fetch_urls_git() {
if [ "${_url_spec#*@}" != "${_url_spec}" ]; then
_git_branch=${_url_spec#*@};
fi;
- exp_rtl_fetch_url_git "${_tgtdir}" "${_subdir}" \
+ rtlp_fetch_url_git "${_tgtdir}" "${_subdir}" \
"${_url}" "${_git_branch}";
done;
};
# N.B. URLs ($1) may contain `?' or '&' characters.
rtl_fetch_url_wget() {
- local _url="${1}" _sha256sum_src="${2}" _target_fname="${3}" _sha256sum_dst="";
+ local _url="${1}" _sha256sum_src="${2}" _target_fname="${3}" _target_fname_full="" RTL_CHECK_DIGEST_DIGEST="";
if [ "${ARG_FETCH_FORCE}" = "offline" ]; then
return 0;
- elif [ -z "${_target_fname}" ]; then
- _target_fname="$(rtl_basename "${_url}")";
- fi;
- _url_dst="${BUILD_DLCACHEDIR}/${_target_fname}";
- (set -o errexit -o noglob -o nounset;
- rtl_flock_acquire 4 || exit "${?}";
- trap "_rc=\"\${?}\" ;rm -f \"${_url_dst}.fetching\"; exit \"\${_rc}\";" EXIT;
- if [ ! -e "${_url_dst}.fetched" ]; then
- wget ${DEFAULT_WGET_ARGS} -O "${_url_dst}" "${_url}";
- if [ -n "${_sha256sum_src}" ]; then
- set -- $(sha256sum "${_url_dst}");
- if [ "${_sha256sum_dst:=${1}}" != "${_sha256sum_src}" ]; then
+ else if [ -z "${_target_fname}" ]; then
+ _target_fname="$(rtl_basename "${_url}")";
+ fi;
+ _target_fname_full="${BUILD_DLCACHEDIR}/${_target_fname}";
+ (set -o errexit -o noglob -o nounset;
+ rtl_flock_acquire 4 || exit "${?}";
+ 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}";
+ if [ -n "${_sha256sum_src}" ]\
+ && ! rtl_check_digest "${_target_fname_full}" "${_sha256sum_src}"; then
rtl_log_msg fatalexit "Error: hash mismatch for URL \`%s' (downloaded file: %s, from build variables: %s.)"\
- "${_url}" "${_sha256sum_dst}" "${_sha256sum_src}";
+ "${_url}" "${RTL_CHECK_DIGEST_DIGEST}" "${_sha256sum_src}";
+ else
+ printf "%s" "${RTL_CHECK_DIGEST_DIGEST}" > "${_target_fname_full}.fetched";
fi;
- fi;
- rtl_fileop touch "${_url_dst}.fetched";
- fi;) 4<>"${_url_dst}.fetching";
+ fi;) 4<>"${_target_fname_full}.fetching";
+ fi;
};
# vim:filetype=sh