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>btrfsvols
parent
7af200a16a
commit
9558e2fce7
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
# This file is only used by update/project/trees
|
# 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"
|
tmp_git_dir="${PWD}/tmp/gitclone"
|
||||||
|
|
||||||
fetch_project_trees()
|
fetch_project_trees()
|
||||||
|
@ -58,16 +58,27 @@ prepare_new_tree()
|
||||||
{
|
{
|
||||||
printf "Creating %s tree %s (%s)\n" "${project}" "${tree}" "${_target}"
|
printf "Creating %s tree %s (%s)\n" "${project}" "${tree}" "${_target}"
|
||||||
|
|
||||||
x_ cp -R "src/${project}/${project}" "src/${project}/${tree}"
|
rm -Rf "${tmp_git_dir%/*}" || \
|
||||||
git_reset_rev "src/${project}/${tree}" "${rev}"
|
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
|
if [ -f ".gitmodules" ]; then
|
||||||
git submodule update --init --checkout || \
|
git submodule update --init --checkout || \
|
||||||
err "prepare_new_tree ${project}/${tree}: !submodules"
|
err "prepare_new_tree ${project}/${tree}: !submodules"
|
||||||
fi
|
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()
|
fetch_project_repo()
|
||||||
|
@ -107,7 +118,9 @@ clone_project()
|
||||||
git clone ${bkup_url} "${tmp_git_dir}" || \
|
git clone ${bkup_url} "${tmp_git_dir}" || \
|
||||||
err "clone_project: could not download ${project}"
|
err "clone_project: could not download ${project}"
|
||||||
git_reset_rev "${tmp_git_dir}" "${rev}"
|
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}"
|
x_ rm -Rf "${loc}"
|
||||||
[ "${loc}" = "${loc%/*}" ] || x_ mkdir -p ${loc%/*}
|
[ "${loc}" = "${loc%/*}" ] || x_ mkdir -p ${loc%/*}
|
||||||
|
@ -137,17 +150,18 @@ git_am_patches()
|
||||||
for patch in "${patchdir}/"*; do
|
for patch in "${patchdir}/"*; do
|
||||||
[ -L "${patch}" ] && continue
|
[ -L "${patch}" ] && continue
|
||||||
[ -f "${patch}" ] || continue
|
[ -f "${patch}" ] || continue
|
||||||
patchfail="n"
|
|
||||||
git am "${patch}" || patchfail="y"
|
git am "${patch}" || patchfail="y"
|
||||||
if [ "${patchfail}" = "y" ]; then
|
if [ "${patchfail}" = "y" ]; then
|
||||||
git am --abort || err "${sdir}: !git am --abort"
|
git am --abort || err "${sdir}: !git am --abort"
|
||||||
err "!git am ${patch} -> ${sdir}"
|
err "!git am ${patch} -> ${sdir}"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
)
|
) || err "PATCH FAILURE"
|
||||||
for patches in "${patchdir}/"*; do
|
for patches in "${patchdir}/"*; do
|
||||||
[ -L "${patches}" ] && continue
|
[ -L "${patches}" ] && continue
|
||||||
[ ! -d "${patches}" ] && continue
|
[ ! -d "${patches}" ] && continue
|
||||||
git_am_patches "${sdir}" "${patches}"
|
git_am_patches "${sdir}" "${patches}"
|
||||||
done
|
done
|
||||||
|
[ "${patchfail}" = "y" ] && return 1
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue