From dc5315c34108016c0c833f4262da8c72108a826b Mon Sep 17 00:00:00 2001 From: Didier Spezia Date: Sat, 2 Jan 2016 14:26:13 +0000 Subject: [PATCH] build: prevent the entire repo to be wiped out by cgo test scripts Following the parallelization of some tests, a race condition can occur in testcarchive, testshared and testcshared. In some cases, it can result in the go env GOROOT command returning corrupted data, which are then passed to a rm command. Make the shell script more robust by not trusting the result of the go env GOROOT command. It does not really fix the issue, but at least prevent the entire repository to be deleted. Updates #13789 Change-Id: Iaf04a7bd078ed3a82e724e35c4b86e6f756f2a2f Reviewed-on: https://go-review.googlesource.com/18173 TryBot-Result: Gobot Gobot Reviewed-by: Russ Cox --- misc/cgo/testcshared/test.bash | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/misc/cgo/testcshared/test.bash b/misc/cgo/testcshared/test.bash index 63ceb29cf9..162a62d80e 100755 --- a/misc/cgo/testcshared/test.bash +++ b/misc/cgo/testcshared/test.bash @@ -16,6 +16,11 @@ fi goos=$(go env GOOS) goarch=$(go env GOARCH) +goroot=$(go env GOROOT) +if [ ! -d "$goroot" ]; then + echo 'misc/cgo/testcshared/test.bash cannnot find GOROOT' 1>&2 + exit 1 +fi # Directory where cgo headers and outputs will be installed. # The installation directory format varies depending on the platform. @@ -30,10 +35,10 @@ androidpath=/data/local/tmp/testcshared-$$ function cleanup() { rm -f libgo.$libext libgo2.$libext libgo4.$libext libgo.h libgo4.h rm -f testp testp2 testp3 testp4 - rm -rf pkg $(go env GOROOT)/${installdir} + rm -rf pkg "${goroot}/${installdir}" if [ "$goos" == "android" ]; then - adb shell rm -rf $androidpath + adb shell rm -rf "$androidpath" fi } trap cleanup EXIT -- 2.50.0