update/project/trees: simplified error handling

Signed-off-by: Leah Rowe <leah@libreboot.org>
btrfsvols
Leah Rowe 2023-10-02 05:21:20 +01:00
parent d38b958d7a
commit 67ac799d49
1 changed files with 13 additions and 33 deletions

View File

@ -11,7 +11,7 @@ set -u -e
. "include/git.sh" . "include/git.sh"
. "include/option.sh" . "include/option.sh"
eval "$(setvars "" _target tree rev project cfgsdir)" eval "$(setvars "" _target tree rev project cfgsdir _xm)"
main() main()
{ {
@ -55,10 +55,10 @@ fetch_config()
_target=${1} _target=${1}
while true; do while true; do
rev="undefined" eval "$(setvars "" rev tree)"
tree="undefined" _xm="fetch_config ${project}/${_target}"
check_config_for_target "${_target}" || return 1 check_config_for_target "${_target}"
# This is to override $rev and $tree # This is to override $rev and $tree
. "${cfgsdir}/${_target}/target.cfg" || \ . "${cfgsdir}/${_target}/target.cfg" || \
@ -67,42 +67,22 @@ fetch_config()
if [ "${_target}" != "${tree}" ]; then if [ "${_target}" != "${tree}" ]; then
_target="${tree}" _target="${tree}"
continue continue
elif [ "${tree}" = "undefined" ]; then
printf "ERROR (fetch_config): download/%s:" \
"${project}" 1>&2
printf " tree name undefined for '%s\n'" \
"${_target}" 1>&2
return 1
elif [ "${rev}" = "undefined" ]; then
printf "ERROR (fetch_config): download/%s:" \
"${project}" 1>&2
printf " commit ID undefined for '%s'\n" \
"${_target}" 1>&2
return 1
else
break
fi fi
[ -z ${tree} ] && err "${_xm}: tree undefined"
[ -z ${rev} ] && err "${_xm}: revision undefined"
break
done done
} }
check_config_for_target() check_config_for_target()
{ {
_target=${1} [ -f "${cfgsdir}/${1}/target.cfg" ] || \
err "${_xm} check: target.cfg does not exist"
if [ ! -f "${cfgsdir}/${_target}/target.cfg" ]; then [ -f "${cfgsdir}/${1}/seen" ] && \
printf "ERROR: download/%s: target.cfg does not" \ err "${_xm} check: infinite loop in tree definitions"
"${project}" 1>&2
printf " exist for '%s'\n" "${_target}" 1>&2 x_ touch "${cfgsdir}/${1}/seen"
return 1
elif [ -f "${cfgsdir}/${_target}/seen" ]; then
printf "ERROR: download/%s: logical loop:" "${project}" 1>&2
printf " '%s' target.cfg refers to another tree," "${_target}" \
1>&2
printf " which ultimately refers back to '%s'." "${_target}" \
1>&2
return 1
fi
x_ touch "${cfgsdir}/${_target}/seen"
} }
fetch_from_upstream() fetch_from_upstream()