From ddab63e3840e6ed6a17bf05ef79955b68244fa17 Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Thu, 16 Apr 2015 21:48:03 -0400 Subject: [PATCH] Fixes #1: Add a mutex to prevent multiple builds --- yoctobuild.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/yoctobuild.go b/yoctobuild.go index 4049f0b..364ebeb 100644 --- a/yoctobuild.go +++ b/yoctobuild.go @@ -15,6 +15,7 @@ import ( "os" "os/exec" "path/filepath" + "sync" "time" "github.com/gorilla/mux" @@ -26,7 +27,8 @@ var ( addr = flag.String("addr", ":3001", "Address to serve on") secret = flag.String("secret", "12345", "Secret to authorize builds") - projects map[string]*project + projects map[string]*project + buildMutex sync.Mutex ) type project struct { @@ -38,6 +40,7 @@ type project struct { } func runBuild(name string) { + buildMutex.Lock() steps := fmt.Sprintf("mkdir -p %s; cd %s; %s", name, name, projects[name].Before) script := bytes.NewBufferString(steps) @@ -58,6 +61,7 @@ func runBuild(name string) { if err == nil { runPostBuild(name) } + buildMutex.Unlock() } func runPostBuild(name string) {