apply-patches.sh: detect missing patches

The "patch" command returns an error code only if patches fail
to apply. Therefore the pipleline "cat <patchfile> | patch ..."
does not fail, even if <patchfile> is missing. Fix this by
adding an explicit check for patch file existence.

Based on feedback from buildroot mailing list, also change the
existing check for unsupported patch format into a fatal error.

Signed-off-by: Ralph Siemsen <ralphs@netwinder.org>
Signed-off-by: Peter Korsgaard <jacmet@sunsite.dk>
This commit is contained in:
Ralph Siemsen 2013-09-15 10:13:14 -04:00 committed by Peter Korsgaard
parent 6f1882deb4
commit d245fbb41d

View File

@ -73,13 +73,17 @@ function apply_patch {
*.patch*) *.patch*)
type="patch"; uncomp="cat"; ;; type="patch"; uncomp="cat"; ;;
*) *)
echo "Unsupported format file for ${patch}, skip it"; echo "Unsupported format file for ${path}/${patch}";
return 0; exit 1;
;; ;;
esac esac
echo "" echo ""
echo "Applying $patch using ${type}: " echo "Applying $patch using ${type}: "
echo $patch >> ${builddir}/.applied_patches_list if [ ! -e "${path}/$patch" ] ; then
echo "Error: missing patch file ${path}/$patch"
exit 1
fi
echo $patch >> ${builddir}/.applied_patches_list
${uncomp} "${path}/$patch" | patch -g0 -p1 -E -d "${builddir}" -t ${uncomp} "${path}/$patch" | patch -g0 -p1 -E -d "${builddir}" -t
if [ $? != 0 ] ; then if [ $? != 0 ] ; then
echo "Patch failed! Please fix ${patch}!" echo "Patch failed! Please fix ${patch}!"
@ -96,7 +100,7 @@ function scan_patchdir {
# to apply patches. Skip line starting with a dash. # to apply patches. Skip line starting with a dash.
if [ -e "${path}/series" ] ; then if [ -e "${path}/series" ] ; then
for i in `grep -Ev "^#" ${path}/series 2> /dev/null` ; do for i in `grep -Ev "^#" ${path}/series 2> /dev/null` ; do
apply_patch "$path" "$i" || exit 1 apply_patch "$path" "$i"
done done
else else
for i in `cd $path; ls -d $patches 2> /dev/null` ; do for i in `cd $path; ls -d $patches 2> /dev/null` ; do
@ -109,7 +113,7 @@ function scan_patchdir {
tar -C "$unpackedarchivedir" -xaf "${path}/$i" tar -C "$unpackedarchivedir" -xaf "${path}/$i"
scan_patchdir "$unpackedarchivedir" scan_patchdir "$unpackedarchivedir"
else else
apply_patch "$path" "$i" || exit 1 apply_patch "$path" "$i"
fi fi
done done
fi fi