summaryrefslogtreecommitdiffhomepage
path: root/subr.rtl/rtl_fetch.subr
blob: 7946b7c70b54dd72ef8b245220b2eab90b45752a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#
# Copyright (c) 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 Lucía Andrea Illanes Albornoz <lucia@luciaillanes.de>
# set +o errexit -o noglob -o nounset is assumed.
#

#
# rtl_fetch_clean_dlcache() - clean download cache for single package
# @_dlcachedir:		absolute pathname to download cache directory
# @_name:		single item name
# @_fname_base:		optional single item archive filename
# @_urls_git:		optional list of item Git URL(s)
#
# Returns:		zero (0) on success, non-zero (>0) on failure
#
rtl_fetch_clean_dlcache() {
	local	_pfdcd_dlcachedir="${1}" _pfdcd_name="${2}"		\
		_pfdcd_fname_base="${3}" _pfdcd_urls_git="${4}"		\
		_pfdcd_fname="" _pfdcd_skipfl=0 _pfdcd_url_spec=""	\
		_pfdcd_url_subdir="";

	for _pfdcd_fname in	\
			$(cd "${_pfdcd_dlcachedir}/${_pfdcd_name}" 2>/dev/null &&
			 find -maxdepth 1 -mindepth 1				\
			${_pfdcd_fname_base:+-not -name "${_pfdcd_fname_base}"}	\
			${_pfdcd_fname_base:+-not -name "${_pfdcd_fname_base}.fetched"});
	do
		_pfdcd_fname="${_pfdcd_fname#./}"; _pfdcd_skipfl=0;

		for _pfdcd_url_spec in ${_pfdcd_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;
		done;

		if [ "${_pfdcd_skipfl}" -eq 0 ]; then
			_pfdcd_fname="${_pfdcd_dlcachedir}/${_pfdcd_name}/${_pfdcd_fname}";
			rtl_log_msg "verbose" "${MSG_rtl_fetch_rm_redundant}" "${_pfdcd_fname}" "${_pfdcd_name}";
			rtl_fileop rm "${_pfdcd_fname}";
		fi;
	done;

	return 0;
};

#
# rtl_fetch_dlcache_subdir() - create download cache subdirectory for single package
# @_dlcachedir:		absolute pathname to download cache directory
# @_name:		single item name
# @_inherit_from:	optional name of item @_name inherits from
#
# Returns:		zero (0) on success, non-zero (>0) on failure
#
rtl_fetch_dlcache_subdir() {
	local	_rfds_dlcachedir="${1}" _rfds_name="${2}" _rfds_inherit_from="${3}";

	if [ "${_rfds_inherit_from:+1}" = 1 ]\
	&& ! [ -e "${_rfds_dlcachedir}/${_rfds_name}" ]\
	&& ! rtl_fileop ln_symbolic "${_rfds_inherit_from}" "${_rfds_dlcachedir}/${_rfds_name}";
	then
		return 1;
	elif [ "${_rfds_inherit_from:+1}" != 1 ]\
	&& ! [ -e "${_rfds_dlcachedir}/${_rfds_name}" ]\
	&& ! rtl_fileop mkdir "${_rfds_dlcachedir}/${_rfds_name}";
	then
		return 1;
	else
		return 0;
	fi;
};

# vim:filetype=sh textwidth=0