diff --git a/diskimage_builder/lib/common-functions b/diskimage_builder/lib/common-functions index c33d4724..ac71350f 100644 --- a/diskimage_builder/lib/common-functions +++ b/diskimage_builder/lib/common-functions @@ -346,7 +346,7 @@ function unmount_dir { if [ ! -d $dir ]; then echo "*** $dir is not a directory" - return 1 + return 0 fi # get rid of any symlink elements in the incoming path, because diff --git a/diskimage_builder/lib/img-functions b/diskimage_builder/lib/img-functions index d1435438..d1163904 100644 --- a/diskimage_builder/lib/img-functions +++ b/diskimage_builder/lib/img-functions @@ -121,9 +121,7 @@ function finalise_base () { fi fi # Cleanup /tmp in the guest, so there is less cruft left there - if [ -d "$TMP_MOUNT_PATH/tmp" ]; then - unmount_dir $TMP_MOUNT_PATH/tmp - fi + unmount_dir $TMP_MOUNT_PATH/tmp find $TMP_MOUNT_PATH/tmp -maxdepth 1 -mindepth 1 | xargs sudo rm -rf --one-file-system # Truncate /var/log files in preparation for first boot sudo find ${TMP_MOUNT_PATH}/var/log -type f -exec cp /dev/null '{}' \; diff --git a/tests/run_dib_library_tests.sh b/tests/run_dib_library_tests.sh index a44408c4..c8f0549a 100755 --- a/tests/run_dib_library_tests.sh +++ b/tests/run_dib_library_tests.sh @@ -6,7 +6,7 @@ # need a human in the loop. Thus it's mostly useful for developers # during testing, but not so great for CI -source ../lib/common-functions +source ../diskimage_builder/lib/common-functions # # Directory mounting and unmounting @@ -44,6 +44,14 @@ else echo "*** PASS all directories unmounted" fi +# unmount missing dir +if unmount_dir /this/path/does/not/exist/but/this/should/not/fail; then + echo "*** PASS unmount_dir ignored a missing path" +else + echo "*** FAILED unmount_dir should ignore missing paths" + return 1 +fi + # cleanup rm -rf $TMP_DIR