From 59d3d736a7c6cf77a52cc1bcbd5b3a2ec85b5b20 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Thu, 12 Jan 2012 18:50:39 -0500 Subject: [PATCH] get_latest_image.sh: error out when image dirs are missing Every consumer that I can find of get_latest_image.sh expects this script to output something useful. Many don't check the result and end up spitting out unhelpful messages when it doesn't. So make a missing images dir fatal for this script so everyone on top of us gets this checking for free. If, in the future, someone actually wants this to output nothing when there's nothing found, we can add a dedicated flag. That mode of operation is a lot less common than having it die by default. BUG=None TEST=delete image tree, run ./get_latest_image.sh --board=${BOARD}, see it fail nicely TEST=delete image tree, run ./image_to_vm.sh --board=${BOARD}, see it fail nicely Change-Id: I0a2ffd0b9084297b6d2346f02dbdb7bd0ef667bf Reviewed-on: https://gerrit.chromium.org/gerrit/15589 Reviewed-by: David James Reviewed-by: Chris Sosa Tested-by: Mike Frysinger Commit-Ready: Mike Frysinger --- get_latest_image.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/get_latest_image.sh b/get_latest_image.sh index 1044caaf88..66916b3545 100755 --- a/get_latest_image.sh +++ b/get_latest_image.sh @@ -43,12 +43,18 @@ fi IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}" -# If there are no images, return nothing -[ -d $IMAGES_DIR ] || exit 0 +# If there are no images, error out since presumably the +# caller isn't doing this for fun. +if [[ ! -d ${IMAGES_DIR} ]] ; then + die "${IMAGES_DIR} does not exist; have you run ./build_image?" +fi # Use latest link if it exists, otherwise most recently changed dir if [ -L ${IMAGES_DIR}/latest ] ; then - DEFAULT_FROM="${IMAGES_DIR}/`readlink ${IMAGES_DIR}/latest`" + if ! dst=$(readlink "${IMAGES_DIR}"/latest) ; then + die "Could not read ${IMAGES_DIR}/latest; have you run ./build_image?" + fi + DEFAULT_FROM="${IMAGES_DIR}/${dst}" else DEFAULT_FROM=$(ls -dt "$IMAGES_DIR"/*/ | head -1) fi