Blame subr/pkg_fetch_download.subr

Lucio Andrés Illanes Albornoz (arab, vxp) 570129
#
Lucio Andrés Illanes Albornoz e1d469
# set +o errexit -o noglob -o nounset is assumed.
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
#
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
Lucio Andrés Illanes Albornoz 2c5ce2
pkg_fetch_download_clean_dlcache() {
Lucio Andrés Illanes Albornoz 2c5ce2
	local	_dlcachedir="${1}" _pkg_name="${2}" _pkg_fname="${3}" _pkg_urls_git="${4}"\
Lucio Andrés Illanes Albornoz 986162
		_fname="" _skipfl=0 _url_spec="" _url_subdir="";
Lucio Andrés Illanes Albornoz 2c5ce2
Lucio Andrés Illanes Albornoz 84398b
	for _fname in $(cd "${_dlcachedir}/${_pkg_name}" && find		\
Lucio Andrés Illanes Albornoz 986162
			-maxdepth 1						\
Lucio Andrés Illanes Albornoz 84398b
			-mindepth 1						\
Lucio Andrés Illanes Albornoz 84398b
			${_pkg_fname:+-not -name "${_pkg_fname}"}		\
Lucio Andrés Illanes Albornoz 986162
			${_pkg_fname:+-not -name "${_pkg_fname}.fetched"}); do
Lucio Andrés Illanes Albornoz 986162
		_fname="${_fname#./}"; _skipfl=0;
Lucio Andrés Illanes Albornoz 986162
		for _url_spec in ${_pkg_urls_git}; do
Lucio Andrés Illanes Albornoz 986162
			_url_subdir="${_url_spec%%=*}"; _url_subdir="${_url_subdir##*/}";
Lucio Andrés Illanes Albornoz 986162
			if [ "${_fname%.git}" = "${_url_subdir}" ]; then
Lucio Andrés Illanes Albornoz 986162
				_skipfl=1; break;
Lucio Andrés Illanes Albornoz 986162
			fi;
Lucio Andrés Illanes Albornoz 986162
		done;
Lucio Andrés Illanes Albornoz 986162
		if [ "${_skipfl}" -eq 0 ]; then
Lucio Andrés Illanes Albornoz 986162
			_fname="${_dlcachedir}/${_pkg_name}/${_fname}";
Lucio Andrés Illanes Albornoz 986162
			rtl_log_msg notice "Deleting redundant file \`%s' for package \`%s'." "${_fname}" "${_pkg_name}";
Lucio Andrés Illanes Albornoz 986162
			rtl_fileop rm "${_fname}";
Lucio Andrés Illanes Albornoz 986162
		fi;
Lucio Andrés Illanes Albornoz 2c5ce2
	done;
Lucio Andrés Illanes Albornoz 2c5ce2
};
Lucio Andrés Illanes Albornoz 2c5ce2
Lucio Andrés Illanes Albornoz 10ff54
pkg_fetch_download_dlcache_subdir() {
Lucio Andrés Illanes Albornoz 10ff54
	if [ -n "${PKG_INHERIT_FROM:-}" ]\
Lucio Andrés Illanes Albornoz 10ff54
	&& ! [ -e "${BUILD_DLCACHEDIR}/${PKG_NAME}" ]\
Lucio Andrés Illanes Albornoz 10ff54
	&& ! rtl_fileop ln_symbolic "${PKG_INHERIT_FROM}" "${BUILD_DLCACHEDIR}/${PKG_NAME}"; then
Lucio Andrés Illanes Albornoz 10ff54
		return 1;
Lucio Andrés Illanes Albornoz 10ff54
	elif [ -z "${PKG_INHERIT_FROM:-}" ]\
Lucio Andrés Illanes Albornoz 10ff54
	&& ! [ -e "${BUILD_DLCACHEDIR}/${PKG_NAME}" ]\
Lucio Andrés Illanes Albornoz 10ff54
	&& ! rtl_fileop mkdir "${BUILD_DLCACHEDIR}/${PKG_NAME}"; then
Lucio Andrés Illanes Albornoz 10ff54
		return 1;
Lucio Andrés Illanes Albornoz 10ff54
	else
Lucio Andrés Illanes Albornoz 10ff54
		return 0;
Lucio Andrés Illanes Albornoz 10ff54
	fi;
Lucio Andrés Illanes Albornoz 10ff54
};
Lucio Andrés Illanes Albornoz 10ff54
Lucio Andrés Illanes Albornoz d279a9
pkg_fetch_download() {
Lucio Andrés Illanes Albornoz b63b9b
	if [ "${ARG_FETCH_FORCE:-}" != "offline" ]; then
Lucio Andrés Illanes Albornoz b63b9b
		if [ -n "${PKG_URL:-}" ]; then
Lucio Andrés Illanes Albornoz 10ff54
			if ! pkg_fetch_download_dlcache_subdir; then
Lucio Andrés Illanes Albornoz 10ff54
				return 1;
Lucio Andrés Illanes Albornoz 10ff54
			elif ! rtl_fetch_url_wget	\
Lucio Andrés Illanes Albornoz 10ff54
					"${PKG_URL}" "${PKG_SHA256SUM}" "${BUILD_DLCACHEDIR}/${PKG_NAME}"\
Lucio Andrés Illanes Albornoz 368962
					"${PKG_FNAME}" "${PKG_NAME}" "${PKG_MIRRORS:-}"; then
Lucio Andrés Illanes Albornoz b63b9b
				return 1;
Lucio Andrés Illanes Albornoz b63b9b
			fi;
Lucio Andrés Illanes Albornoz bf9edf
		fi;
Lucio Andrés Illanes Albornoz b63b9b
		if [ -n "${PKG_URLS_GIT:-}" ]; then
Lucio Andrés Illanes Albornoz 10ff54
			if ! pkg_fetch_download_dlcache_subdir; then
Lucio Andrés Illanes Albornoz 10ff54
				return 1;
Lucio Andrés Illanes Albornoz 10ff54
			elif ! rtl_fetch_urls_git	\
Lucio Andrés Illanes Albornoz 10ff54
					"${BUILD_DLCACHEDIR}/${PKG_NAME}" "${DEFAULT_GIT_ARGS}" "${PKG_BASE_DIR}"\
Lucio Andrés Illanes Albornoz 368962
					"${PKG_NAME}" "${PKG_MIRRORS_GIT:-}" ${PKG_URLS_GIT}; then
Lucio Andrés Illanes Albornoz b63b9b
				return 1;
Lucio Andrés Illanes Albornoz b63b9b
			fi;
Lucio Andrés Illanes Albornoz bf9edf
		fi;
Lucio Andrés Illanes Albornoz 84398b
		pkg_fetch_download_clean_dlcache "${BUILD_DLCACHEDIR}" "${PKG_NAME}" "${PKG_FNAME:-}" "${PKG_URLS_GIT:-}";
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
	fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
};
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
# vim:filetype=sh