From d81ac5328b395deaf1e041381e1bbabb0246c3f3 Mon Sep 17 00:00:00 2001 From: George Danchev Date: Fri, 8 Jul 2011 16:01:17 +0000 Subject: [PATCH] take extra measures we are in sepf-generated data directory before removing self-generated cruft --- .../trunk/releng/inc/releng_getopts.inc | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/libisoburn/trunk/releng/inc/releng_getopts.inc b/libisoburn/trunk/releng/inc/releng_getopts.inc index 45c67aaf..cc1ad35e 100644 --- a/libisoburn/trunk/releng/inc/releng_getopts.inc +++ b/libisoburn/trunk/releng/inc/releng_getopts.inc @@ -27,9 +27,34 @@ cleanup() { # directory before removing whatever self-generated stuff if [ -d "${GEN_DATA_DIR}" ]; then cd "${START_DIR_DONT_CHANGE}" || exit 2 - chmod +w -R ${GEN_DATA_DIR} - rm -rf ${GEN_DATA_DIR} - printf "${SELF}: Removed (self-generated) %s\n" ${GEN_DATA_DIR} + + # Verify once again we are in the releng_generated_data directory + # Check for both returned code of grep and returned matching string + READ_CANON_EXISTS=`readlink -e "${GEN_DATA_DIR}"` + DIR_NAME_GEN_DATA=`dirname "${READ_CANON_EXISTS}"` + set +e + RET_NON_EMPTY_STRING=`echo "${DIR_NAME_GEN_DATA}" | grep -P "\w+\/releng_generated_data$"` + GREP_RET_GEN_DATA="$?" + case "${GREP_RET_GEN_DATA}" in + 0) + if [ x"${RET_NON_EMPTY_STRING}" != x"" ]; then + # now call the nastiness + chmod +w -R ${GEN_DATA_DIR} + rm -rf ${GEN_DATA_DIR} + printf "${SELF}: Removed (self-generated) %s\n" ${GEN_DATA_DIR} + else + printf "${SELF}: FAIL: Safety check for being in releng_generated_data directory.\n" + printf "${SELF}: FAIL: GREP returned empty string: ${RET_NON_EMPTY_STRING}.\n" + printf "${SELF}: FAIL: Skipped trying to remove ${GEN_DATA_DIR} directory. Exiting.\n" + fi + ;; + *) + printf "${SELF}: FAIL: Safety check for being in releng_generated_data directory.\n" + printf "${SELF}: FAIL: GREP returned code: ${GREP_RET_GEN_DATA}.\n" + printf "${SELF}: FAIL: Skipped trying to remove ${GEN_DATA_DIR} directory. Exiting.\n" + exit 30 + ;; + esac else printf "${SELF}: ${GEN_DATA_DIR} does not exist. Nothing to clean.\n" fi