summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2023-12-11 04:59:44 +0000
committerLeah Rowe <leah@libreboot.org>2023-12-11 05:01:39 +0000
commit9558e2fce790b044c33c54dfc58780a66e98b770 (patch)
tree27c3ab9d0ff1a4d903f4d08b68c72c26901d07af /include
parent7af200a16aa2f8221f7b177add9cd7bfce39b4da (diff)
improved safety/error handling on multitree git-am
update/trees wasn't correctly returning non-zero status, even though it was printing an error message, when git-am failed. this is due to the way subshells work, and it was overlooked in previous auditing. additionally: don't directly copy trees to the destination, instead patch/reset first, then copy only under normal condition, just as with single-tree projects. when running build/roms, the script would continue after a bad git-am, without exit. this patch fixes it in the most paranoid way possible. i'm now fairly confident that lbmk will fail gracefully and efficiently, under error conditions. this should prevent bad image builds. Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'include')
-rwxr-xr-xinclude/git.sh30
1 files changed, 22 insertions, 8 deletions
diff --git a/include/git.sh b/include/git.sh
index fa53fed1..49148224 100755
--- a/include/git.sh
+++ b/include/git.sh
@@ -4,7 +4,7 @@
# This file is only used by update/project/trees
-eval "$(setvars "" _target rev _xm loc url bkup_url depend)"
+eval "$(setvars "" _target rev _xm loc url bkup_url depend patchfail)"
tmp_git_dir="${PWD}/tmp/gitclone"
fetch_project_trees()
@@ -58,16 +58,27 @@ prepare_new_tree()
{
printf "Creating %s tree %s (%s)\n" "${project}" "${tree}" "${_target}"
- x_ cp -R "src/${project}/${project}" "src/${project}/${tree}"
- git_reset_rev "src/${project}/${tree}" "${rev}"
+ rm -Rf "${tmp_git_dir%/*}" || \
+ err "prepare_new_tree ${project}/${tree}: can't rm tmpclone"
+ mkdir "${tmp_git_dir%/*}" || \
+ err "prepare_new_tree ${project}/${tree}: can't mkdir tmp"
+ cp -R "src/${project}/${project}" "${tmp_git_dir}" || \
+ err "prepare_new_tree ${project}/${tree}: can't make tmpclone"
+ git_reset_rev "${tmp_git_dir}" "${rev}"
(
- x_ cd "src/${project}/${tree}"
+ cd "${tmp_git_dir}" || \
+ err "prepare_new_tree ${project}/${tree}: can't cd tmpclone"
if [ -f ".gitmodules" ]; then
git submodule update --init --checkout || \
err "prepare_new_tree ${project}/${tree}: !submodules"
fi
)
- git_am_patches "$PWD/src/$project/$tree" "$PWD/$cfgsdir/$tree/patches"
+ git_am_patches "${tmp_git_dir}" "$PWD/$cfgsdir/$tree/patches" || \
+ err "prepare_new_tree ${project}/${tree}: patch fail"
+ [ "${patchfail}" = "y" ] && err "PATCH FAIL"
+
+ mv "${tmp_git_dir}" "src/${project}/${tree}" || \
+ err "prepare_new_tree ${project}/${tree}: can't copy tmpclone"
}
fetch_project_repo()
@@ -107,7 +118,9 @@ clone_project()
git clone ${bkup_url} "${tmp_git_dir}" || \
err "clone_project: could not download ${project}"
git_reset_rev "${tmp_git_dir}" "${rev}"
- git_am_patches "${tmp_git_dir}" "${PWD}/config/${project}/patches"
+ git_am_patches "${tmp_git_dir}" "${PWD}/config/${project}/patches" \
+ || err "clone_project ${project} ${loc}: patch fail"
+ [ "${patchfail}" = "y" ] && err "PATCH FAIL"
x_ rm -Rf "${loc}"
[ "${loc}" = "${loc%/*}" ] || x_ mkdir -p ${loc%/*}
@@ -137,17 +150,18 @@ git_am_patches()
for patch in "${patchdir}/"*; do
[ -L "${patch}" ] && continue
[ -f "${patch}" ] || continue
- patchfail="n"
git am "${patch}" || patchfail="y"
if [ "${patchfail}" = "y" ]; then
git am --abort || err "${sdir}: !git am --abort"
err "!git am ${patch} -> ${sdir}"
fi
done
- )
+ ) || err "PATCH FAILURE"
for patches in "${patchdir}/"*; do
[ -L "${patches}" ] && continue
[ ! -d "${patches}" ] && continue
git_am_patches "${sdir}" "${patches}"
done
+ [ "${patchfail}" = "y" ] && return 1
+ return 0
}