From 557c4cfd005a5bb834f7d72a6389247e3b55157b Mon Sep 17 00:00:00 2001 From: David Gibson Date: Fri, 25 Mar 2022 21:58:02 +1100 Subject: [PATCH] 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 --- src/runtime/go-test.sh | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/runtime/go-test.sh b/src/runtime/go-test.sh index a57255b179..2f6f1865e6 100755 --- a/src/runtime/go-test.sh +++ b/src/runtime/go-test.sh @@ -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 }