From f3d58d9042f82805ac6c944c8ea360e88b3cca4d Mon Sep 17 00:00:00 2001 From: Clark Boylan Date: Fri, 6 Apr 2018 15:04:56 -0700 Subject: [PATCH] Don't use -e to test for what might be broken symlink The behavior of test -e and [[ -e against broken symlinks is to fail even if the symlink exists. However we want to test if the link exists or if there is a file in that location. Therefore switch from test -e to test -L and test -f to check if the file or link exists regardless of link target validity. Change-Id: I84a9b6731eccf950707be50aef464a2de1e33e8e --- diskimage_builder/lib/common-functions | 4 +++- diskimage_builder/lib/img-functions | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/diskimage_builder/lib/common-functions b/diskimage_builder/lib/common-functions index a7f3666dc..dd4efc74d 100644 --- a/diskimage_builder/lib/common-functions +++ b/diskimage_builder/lib/common-functions @@ -342,7 +342,9 @@ function create_base () { # Save resolv.conf as created by the initial install. Note the # .ORIG file is an exported interface -- it may be modified and we # will copy it back in during finalisation of the image. - if [[ -e $TMP_MOUNT_PATH/etc/resolv.conf ]]; then + # Note that we use -L and -f to test here as test (and bash [[) + # return false with -e if the link target does not exist. + if [ -L $TMP_MOUNT_PATH/etc/resolv.conf ] || [ -f $TMP_MOUNT_PATH/etc/resolv.conf ] ; then sudo mv $TMP_MOUNT_PATH/etc/resolv.conf $TMP_MOUNT_PATH/etc/resolv.conf.ORIG fi diff --git a/diskimage_builder/lib/img-functions b/diskimage_builder/lib/img-functions index c861bdd5e..d5f929cf5 100644 --- a/diskimage_builder/lib/img-functions +++ b/diskimage_builder/lib/img-functions @@ -116,7 +116,9 @@ function finalise_base () { # Remove the resolv.conf we created and put the original (or # perhaps modified) version back. sudo rm -f $TMP_MOUNT_PATH/etc/resolv.conf - if [ -e $TMP_MOUNT_PATH/etc/resolv.conf.ORIG ]; then + # Note that we use -L and -f to test here as test (and bash [[) + # return false with -e if the link target does not exist. + if [ -L $TMP_MOUNT_PATH/etc/resolv.conf.ORIG ] || [ -f $TMP_MOUNT_PATH/etc/resolv.conf.ORIG ] ; then sudo mv $TMP_MOUNT_PATH/etc/resolv.conf.ORIG $TMP_MOUNT_PATH/etc/resolv.conf fi fi