runtime: Don't chmod coverage files in Go tests

The go-test.sh script has an explicit chmod command, run as root, to
set the mode of the temporary coverage files to 0644.  AFAICT the
point of this is specifically the 004 bit allowing world read access,
so that we can then merge the temporary coverage file into the main
coverage file.

That's a convoluted way of doing things.  Instead we can just run the tail
command which reads the temporary file as the same user that generated it.

In addition, go-test.sh became root to remove that temporary coverage
file.  This is not necessary, since deleting a regular file just requires
write access to the directory, not the file itself.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
David Gibson 2022-03-25 21:58:02 +11:00
parent 04c8b52e04
commit 557c4cfd00

View File

@ -44,9 +44,6 @@ test_coverage_file="coverage.txt"
# file will be added to the master coverage file.
tmp_coverage_file="${test_coverage_file}.tmp"
# Permissions to create coverage files with
coverage_file_mode=0644
warn()
{
local msg="$*"
@ -135,9 +132,8 @@ test_go_package()
if [ -f "${tmp_coverage_file}" ]; then
# Save these package test results into the
# master coverage file.
run_as_user "$user" chmod "${coverage_file_mode}" "$tmp_coverage_file"
tail -n +2 "$tmp_coverage_file" >> "$test_coverage_file"
run_as_user "$user" rm -f "$tmp_coverage_file"
run_as_user "$user" tail -n +2 "$tmp_coverage_file" >> "$test_coverage_file"
rm -f "$tmp_coverage_file"
fi
}