mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-15 08:07:20 +02:00
Greatly simplify error handling in shell scripts
Instead of having detailed error messages, run most commands through a function that calls err() under fault conditions. Where detail is still required, err() is still called manually. Where it isn't, the error message is simply whatever command was executed to cause the error. This results in a massive sloccount reduction for lbmk; specifically, 178 sloc reduction, or a 8.1% reduction. The total sloccount is now 2022, for shell scripts. Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
@@ -23,11 +23,9 @@ main()
|
||||
|
||||
clone_project
|
||||
[ "${depend}" = "" ] || for d in ${depend} ; do
|
||||
./update project repo ${d} || \
|
||||
fail "Cannot fetch dependency, ${d}, for project, ${name}"
|
||||
xx_ ./update project repo ${d}
|
||||
done
|
||||
|
||||
rm -Rf "${tmp_dir}" || fail "cannot remove tmpdir, ${tmp_dir}"
|
||||
xx_ rm -Rf "${tmp_dir}"
|
||||
}
|
||||
|
||||
verify_config()
|
||||
@@ -39,8 +37,8 @@ verify_config()
|
||||
|
||||
clone_project()
|
||||
{
|
||||
rm -Rf "${tmp_dir}" || fail "clone_project: cannot remove old tmpdir"
|
||||
mkdir -p "${tmp_dir%/*}" || fail "clone_project: can't mkdir"
|
||||
xx_ rm -Rf "${tmp_dir}"
|
||||
xx_ mkdir -p "${tmp_dir%/*}"
|
||||
|
||||
git clone ${url} "${tmp_dir}" || git clone ${bkup_url} "${tmp_dir}" || \
|
||||
fail "clone_project: could not download ${name}"
|
||||
@@ -50,12 +48,9 @@ clone_project()
|
||||
fail "clone_project ${loc}/: cannot apply patches"
|
||||
|
||||
[ ! -d "${loc}" ] || \
|
||||
rm -Rf "${loc}" || \
|
||||
fail "clone_project: Can't remove directory '${loc}'"
|
||||
[ "${loc}" = "${loc%/*}" ] || mkdir -p ${loc%/*} || \
|
||||
fail "clone_project: cannot make directory for ${name}"
|
||||
mv "${tmp_dir}" "${loc}" || \
|
||||
fail "clone_project: could not copy temp file to destination"
|
||||
xx_ rm -Rf "${loc}"
|
||||
[ "${loc}" = "${loc%/*}" ] || xx_ mkdir -p ${loc%/*}
|
||||
xx_ mv "${tmp_dir}" "${loc}"
|
||||
}
|
||||
|
||||
fail()
|
||||
|
||||
Reference in New Issue
Block a user