|
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 |
|
|
|
4243a1 |
#
|
|
|
4243a1 |
# rtl_state_clear() - clear state for item
|
|
|
4243a1 |
# @_workdir: pathname to directory containing state files
|
|
|
4243a1 |
# @_item_name: name of item to clear state for
|
|
|
4243a1 |
#
|
|
|
4243a1 |
# Returns: zero (0) on success, non-zero (>0) on failure
|
|
|
4243a1 |
#
|
|
Lucio Andrés Illanes Albornoz |
c6d6e0 |
rtl_state_clear() {
|
|
|
4243a1 |
local _rsc_workdir="${1}" _rsc_item_name="${2}" \
|
|
|
4243a1 |
_rsc_item_fname="";
|
|
|
e9fa07 |
|
|
|
4243a1 |
for _rsc_item_fname in $(
|
|
|
e9fa07 |
find "${_rsc_workdir}" \
|
|
|
e9fa07 |
-maxdepth 1 \
|
|
|
e9fa07 |
-mindepth 1 \
|
|
|
4243a1 |
-name .${_rsc_item_name}.\* \
|
|
|
e9fa07 |
-type f);
|
|
|
e9fa07 |
do
|
|
|
4243a1 |
rtl_fileop rm "${_rsc_item_fname}";
|
|
Lucio Andrés Illanes Albornoz |
da0364 |
done;
|
|
|
e9fa07 |
return 0;
|
|
Lucio Andrés Illanes Albornoz |
da0364 |
};
|
|
Lucio Andrés Illanes Albornoz |
da0364 |
|
|
|
4243a1 |
#
|
|
|
4243a1 |
# rtl_state_set() - set state for item
|
|
|
4243a1 |
# @_workdir: pathname to directory containing state files
|
|
|
4243a1 |
# @_item_name: name of item to set state for
|
|
|
4243a1 |
# @_state: state to set
|
|
|
4243a1 |
#
|
|
|
4243a1 |
# Returns: zero (0) on success, non-zero (>0) on failure
|
|
|
4243a1 |
#
|
|
Lucio Andrés Illanes Albornoz |
c6d6e0 |
rtl_state_set() {
|
|
|
4243a1 |
local _rss_workdir="${1}" _rss_item_name="${2}" _rss_state="${3}" \
|
|
|
4243a1 |
_rss_done_name_pfx="${1}/.${2}";
|
|
|
e9fa07 |
shift 3;
|
|
Lucio Andrés Illanes Albornoz |
370e98 |
|
|
|
4243a1 |
rtl_fileop touch "${_rss_done_name_pfx}.${_rss_state}";
|
|
Lucio Andrés Illanes Albornoz |
370e98 |
while [ ${#} -ge 1 ]; do
|
|
Lucio Andrés Illanes Albornoz |
370e98 |
if [ "${#1}" -gt 0 ]; then
|
|
|
4243a1 |
rtl_fileop rm "${_rss_done_name_pfx}.${1}";
|
|
Lucio Andrés Illanes Albornoz |
370e98 |
fi; shift;
|
|
Lucio Andrés Illanes Albornoz |
370e98 |
done;
|
|
|
e9fa07 |
return 0;
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
ec19f0 |
};
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
ec19f0 |
|
|
|
4243a1 |
#
|
|
|
4243a1 |
# rtl_state_test() - test state(s) for item
|
|
|
4243a1 |
# @_workdir: pathname to directory containing state files
|
|
|
4243a1 |
# @_item_name: name of item to set state for
|
|
|
4243a1 |
# @_states: state(s) to test for
|
|
|
4243a1 |
# @[_lforce]: one of "ALL" (force all states to test as set,) "LAST" or "" (test all states,)
|
|
|
4243a1 |
# or exclusive list of states to force to test as set
|
|
|
4243a1 |
#
|
|
|
4243a1 |
# Returns: zero (0) if any of state(s) set, non-zero (>0) if none of state(s) set
|
|
|
4243a1 |
#
|
|
Lucio Andrés Illanes Albornoz |
c6d6e0 |
rtl_state_test() {
|
|
|
4243a1 |
local _rst_workdir="${1}" _rst_item_name="${2}" \
|
|
|
4243a1 |
_rst_states="${3}" _rst_lforce="${4:-}" \
|
|
|
4243a1 |
_rst_state="" _rst_done_fname="" IFS="," _rst_rc=0;
|
|
|
4243a1 |
|
|
|
4243a1 |
for _rst_state in ${_rst_states}; do
|
|
|
4243a1 |
_rst_done_fname="${_rst_workdir}/.${_rst_item_name}.${_rst_state}";
|
|
|
4243a1 |
|
|
|
4243a1 |
case "${_rst_lforce}" in
|
|
|
4243a1 |
ALL)
|
|
|
4243a1 |
_rst_rc=1; ;;
|
|
|
4243a1 |
""|LAST)
|
|
|
4243a1 |
rtl_fileop test "${_rst_done_fname}"; _rst_rc="${?}"; ;;
|
|
|
4243a1 |
*)
|
|
|
4243a1 |
rtl_lmatch \$_rst_lforce "${_rst_state}" ",";
|
|
|
e9fa07 |
_rst_rc=$((${?} ? 0 : 1));
|
|
|
4243a1 |
;;
|
|
|
4243a1 |
esac;
|
|
|
4243a1 |
|
|
|
4243a1 |
if [ "${_rst_rc}" -eq 0 ]; then
|
|
|
4243a1 |
break;
|
|
|
4243a1 |
fi;
|
|
|
e9fa07 |
done;
|
|
|
e9fa07 |
return "${_rst_rc}";
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
ec19f0 |
};
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
ec19f0 |
|
|
|
64844b |
# vim:filetype=sh textwidth=0
|