Allow gexec.Build to be called concurrently
Signed-off-by: Jason Keene <jkeene@pivotal.io>
diff --git a/gexec/build.go b/gexec/build.go
index 25b7d51..220c8c4 100644
--- a/gexec/build.go
+++ b/gexec/build.go
@@ -9,9 +9,13 @@
"path"
"path/filepath"
"runtime"
+ "sync"
)
-var tmpDir string
+var (
+ mu sync.Mutex
+ tmpDir string
+)
/*
Build uses go build to compile the package at packagePath. The resulting binary is saved off in a temporary directory.
@@ -60,6 +64,8 @@
gexec. In Ginkgo this is typically done in an AfterSuite callback.
*/
func CleanupBuildArtifacts() {
+ mu.Lock()
+ defer mu.Unlock()
if tmpDir != "" {
os.RemoveAll(tmpDir)
tmpDir = ""
@@ -68,6 +74,8 @@
func temporaryDirectory() (string, error) {
var err error
+ mu.Lock()
+ defer mu.Unlock()
if tmpDir == "" {
tmpDir, err = ioutil.TempDir("", "gexec_artifacts")
if err != nil {