From 43c22803a1ee737d1c1d8d65afd0b9eeff637d29 Mon Sep 17 00:00:00 2001 From: Kris Rambish Date: Mon, 15 Nov 2010 11:26:22 -0800 Subject: [PATCH] Make removing the last ] more full-proof Make removal of last ] more full-proof Change-Id: I002e5ed513066a214fd6353f66e05bf5458f6ad4 BUG=7115 TEST= No file, with --subfolder No file, without --subfolder Empty file File with one config already in it, with --subfolder File with one config and garbage at the end, with --subfolder File with one config and newlines at the end, with --subfolder File with one config, without subfolder Review URL: http://codereview.chromium.org/4688004 --- make_factory_package.sh | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/make_factory_package.sh b/make_factory_package.sh index a62cfe2e3c..57c23a159c 100755 --- a/make_factory_package.sh +++ b/make_factory_package.sh @@ -218,9 +218,28 @@ fi if [ -n "${FLAGS_subfolder}" ] && \ [ -f "${OMAHA_DIR}"/miniomaha.conf"" ] ; then # Remove the ']' from the last line of the file so we can add another config. - sed -i '$d' ${OMAHA_DIR}/miniomaha.conf + while [ -s "${OMAHA_DIR}/miniomaha.conf" ]; do + # If the last line is null + if [ -z "$(tail -1 "${OMAHA_DIR}/miniomaha.conf")" ]; then + sed -i '$d' "${OMAHA_DIR}/miniomaha.conf" + elif [ "$(tail -1 "${OMAHA_DIR}/miniomaha.conf")" != ']' ]; then + sed -i '$d' "${OMAHA_DIR}/miniomaha.conf" + else + break + fi + done + + # Remove the last ] + if [ "$(tail -1 "${OMAHA_DIR}/miniomaha.conf")" = ']' ]; then + sed -i '$d' "${OMAHA_DIR}/miniomaha.conf" + fi + + # If the file is empty, create it from scratch + if [ ! -s "${OMAHA_DIR}/miniomaha.conf" ]; then + echo "config = [" > "${OMAHA_DIR}/miniomaha.conf" + fi else - echo -e "config = [" > ${OMAHA_DIR}/miniomaha.conf + echo "config = [" > "${OMAHA_DIR}/miniomaha.conf" fi if [ -n "${FLAGS_subfolder}" ] ; then