diff --git a/tools/test/test-setup.sh b/tools/test/test-setup.sh index 852b169e3ce909..01487123cf7429 100755 --- a/tools/test/test-setup.sh +++ b/tools/test/test-setup.sh @@ -421,14 +421,15 @@ fi # Zip up undeclared outputs. if [[ -n "$TEST_UNDECLARED_OUTPUTS_ZIP" ]] && cd "$TEST_UNDECLARED_OUTPUTS_DIR"; then - shopt -s dotglob - if [[ "$(echo *)" != "*" ]]; then - # If * found nothing, echo printed the literal *. - # Otherwise echo printed the top-level files and directories. - # Pass files to zip with *, so paths with spaces aren't broken up. - # Remove original files after zipping them. - zip -qrm "$TEST_UNDECLARED_OUTPUTS_ZIP" -- * 2>/dev/null || \ + shopt -s dotglob nullglob + # Capture the contents of TEST_UNDECLARED_OUTPUTS_DIR prior to creating the output.zip + UNDECLARED_OUTPUTS=(*) + if [[ "${#UNDECLARED_OUTPUTS[@]}" != 0 ]]; then + zip -qr "$TEST_UNDECLARED_OUTPUTS_ZIP" -- "${UNDECLARED_OUTPUTS[@]}" 2>/dev/null || \ echo >&2 "Could not create \"$TEST_UNDECLARED_OUTPUTS_ZIP\": zip not found or failed" + # Use 'rm' instead of 'zip -m' so that we don't follow symlinks when deleting the + # contents. + rm -r "${UNDECLARED_OUTPUTS[@]}" fi fi