Skip to content

Commit

Permalink
Preserve symlinks in --zip_undeclared_test_outputs
Browse files Browse the repository at this point in the history
Update tools/test/test-setup.sh to preserve symlinks when performing the
zip of `$TEST_UNDECLARED_OUTPUTS_DIR`.

This fixes a serious bug where an absolute symlink generated in the test
could delete files anywhere on the filesystem.

For example, a `sh_test` containing a line like:

    ln -s "$HOME" "$TEST_UNDECLARED_OUTPUTS_DIR/home"

would have caused the users home directory to be deleted after copying
it in to the output.zip. With this change, the output.zip only contains
a (possibly dangling) symlink, but more importantly the deletions are
limited to the `$TEST_UNDECLARED_OUTPUTS_DIR`.

RELNOTES: `--zip_undeclared_test_outputs` now preserves symlinks when
zipping `$TEST_UNDECLARED_OUTPUTS_DIR`.
  • Loading branch information
alanfalloon committed Oct 25, 2023
1 parent 877f845 commit 2011e36
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion tools/test/test-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ if [[ -n "$TEST_UNDECLARED_OUTPUTS_ZIP" ]] && cd "$TEST_UNDECLARED_OUTPUTS_DIR";
# 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 || \
zip -qrmy "$TEST_UNDECLARED_OUTPUTS_ZIP" -- * 2>/dev/null || \
echo >&2 "Could not create \"$TEST_UNDECLARED_OUTPUTS_ZIP\": zip not found or failed"
fi
fi
Expand Down

0 comments on commit 2011e36

Please sign in to comment.