Blame subr.rtl/rtl_fetch.subr

Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
#
8d7a8a
# Copyright (c) 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 LucĂ­a Andrea Illanes Albornoz <lucia@luciaillanes.de>
Lucio Andrés Illanes Albornoz e1d469
# set +o errexit -o noglob -o nounset is assumed.
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
#
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
550c18
#
550c18
# rtl_fetch_clean_dlcache() - clean download cache for single package
550c18
# @_dlcachedir:		absolute pathname to download cache directory
550c18
# @_name:		single item name
550c18
# @_fname_base:		optional single item archive filename
550c18
# @_urls_git:		optional list of item Git URL(s)
550c18
#
550c18
# Returns:		zero (0) on success, non-zero (>0) on failure
550c18
#
e9fa07
rtl_fetch_clean_dlcache() {
550c18
	local	_pfdcd_dlcachedir="${1}" _pfdcd_name="${2}"		\
550c18
		_pfdcd_fname_base="${3}" _pfdcd_urls_git="${4}"		\
e9fa07
		_pfdcd_fname="" _pfdcd_skipfl=0 _pfdcd_url_spec=""	\
e9fa07
		_pfdcd_url_subdir="";
Lucio Andrés Illanes Albornoz 368962
e9fa07
	for _pfdcd_fname in	\
550c18
			$(cd "${_pfdcd_dlcachedir}/${_pfdcd_name}" 2>/dev/null &&
e9fa07
			 find -maxdepth 1 -mindepth 1				\
550c18
			${_pfdcd_fname_base:+-not -name "${_pfdcd_fname_base}"}	\
550c18
			${_pfdcd_fname_base:+-not -name "${_pfdcd_fname_base}.fetched"});
e9fa07
	do
e9fa07
		_pfdcd_fname="${_pfdcd_fname#./}"; _pfdcd_skipfl=0;
e9fa07
550c18
		for _pfdcd_url_spec in ${_pfdcd_urls_git}; do
e9fa07
			_pfdcd_url_subdir="${_pfdcd_url_spec%%=*}"; _pfdcd_url_subdir="${_pfdcd_url_subdir##*/}";
e9fa07
			if [ "${_pfdcd_fname%.git}" = "${_pfdcd_url_subdir}" ]; then
e9fa07
				_pfdcd_skipfl=1; break;
Lucio Andrés Illanes Albornoz 689d3c
			fi;
e9fa07
		done;
e9fa07
e9fa07
		if [ "${_pfdcd_skipfl}" -eq 0 ]; then
550c18
			_pfdcd_fname="${_pfdcd_dlcachedir}/${_pfdcd_name}/${_pfdcd_fname}";
550c18
			rtl_log_msg "verbose" "${MSG_rtl_fetch_rm_redundant}" "${_pfdcd_fname}" "${_pfdcd_name}";
e9fa07
			rtl_fileop rm "${_pfdcd_fname}";
e9fa07
		fi;
Lucio Andrés Illanes Albornoz b63b9b
	done;
e9fa07
e9fa07
	return 0;
e9fa07
};
e9fa07
550c18
#
550c18
# rtl_fetch_dlcache_subdir() - create download cache subdirectory for single package
550c18
# @_dlcachedir:		absolute pathname to download cache directory
550c18
# @_name:		single item name
550c18
# @_inherit_from:	optional name of item @_name inherits from
550c18
#
550c18
# Returns:		zero (0) on success, non-zero (>0) on failure
550c18
#
e9fa07
rtl_fetch_dlcache_subdir() {
550c18
	local	_rfds_dlcachedir="${1}" _rfds_name="${2}" _rfds_inherit_from="${3}";
e9fa07
550c18
	if [ "${_rfds_inherit_from:+1}" = 1 ]\
550c18
	&& ! [ -e "${_rfds_dlcachedir}/${_rfds_name}" ]\
550c18
	&& ! rtl_fileop ln_symbolic "${_rfds_inherit_from}" "${_rfds_dlcachedir}/${_rfds_name}";
e9fa07
	then
e9fa07
		return 1;
550c18
	elif [ "${_rfds_inherit_from:+1}" != 1 ]\
550c18
	&& ! [ -e "${_rfds_dlcachedir}/${_rfds_name}" ]\
550c18
	&& ! rtl_fileop mkdir "${_rfds_dlcachedir}/${_rfds_name}";
e9fa07
	then
e9fa07
		return 1;
e9fa07
	else
e9fa07
		return 0;
e9fa07
	fi;
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
};
Lucio Andrés Illanes Albornoz (arab, vxp) ec19f0
64844b
# vim:filetype=sh textwidth=0