mirror of
https://github.com/flatcar/scripts.git
synced 2025-11-28 14:01:43 +01:00
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 <davidjames@chromium.org>
Reviewed-by: Chris Sosa <sosa@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
Commit-Ready: Mike Frysinger <vapier@chromium.org>
This commit is contained in:
parent
2b73600f7f
commit
59d3d736a7
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user