From 74a07cac15a4e19285deffe52feafd8f702f6f35 Mon Sep 17 00:00:00 2001 From: Tan Gao Date: Thu, 9 Sep 2010 11:41:30 -0700 Subject: [PATCH] Issue 6577: remove confirmation to delete output directory Change-Id: Ib19986121a8988c6cae23527148a7b5d4a58663e BUG=chromium-os:6577 TEST=(inside chroot) run 4 test cases from src/scripts/, using Ctrl+C to force abort (hence triggering "delete_prompt") a.) (stdin tty) "./build_image --board=x86-generic < /dev/null", expected = no prompt and delete output dir; actual == expected b.) (stdout tty) "./build_image --board=x86-generic > foo.txt", expected = no prompt and delete output dir; actual == expected c.) (normal user case) "./build_image --board=x86-generic", expected = prompt to delete output dir, if y, output dir is removed; actual == expected d.) (normal user case) "./build_image --board=x86-generic", expected = prompt to delete output dir, if N, output dir is NOT removed; actual == expected Review URL: http://codereview.chromium.org/3373003 --- build_image | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/build_image b/build_image index b4a6f1ac62..6e2aa0e8a8 100755 --- a/build_image +++ b/build_image @@ -319,14 +319,21 @@ cleanup() { delete_prompt() { echo "An error occurred in your build so your latest output directory" \ "is invalid." - read -p "Would you like to delete the output directory (y/N)? " SURE - SURE="${SURE:0:1}" # Get just the first character. + + # Only prompt if both stdin and stdout are a tty. If either is not a tty, + # then the user may not be present, so we shouldn't bother prompting. + if tty -s && tty -s <&1; then + read -p "Would you like to delete the output directory (y/N)? " SURE + SURE="${SURE:0:1}" # Get just the first character. + else + SURE="y" + echo "Running in non-interactive mode so deleting output directory." + fi if [ "${SURE}" == "y" ] ; then sudo rm -rf "${OUTPUT_DIR}" echo "Deleted ${OUTPUT_DIR}" else - echo "Not deleting ${OUTPUT_DIR}. Note dev server updates will not work" \ - "until you successfully build another image or delete this directory" + echo "Not deleting ${OUTPUT_DIR}." fi }