go.talks/pkg/socket: fix can't remove temp binary issue
Fixes golang/go#5870.
R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/11012046
diff --git a/pkg/socket/socket.go b/pkg/socket/socket.go
index 49707f7..df573d7 100644
--- a/pkg/socket/socket.go
+++ b/pkg/socket/socket.go
@@ -117,6 +117,7 @@
out chan<- *Message
done chan struct{} // closed when wait completes
run *exec.Cmd
+ bin string
}
// startProcess builds and runs the given program, sending its output
@@ -166,7 +167,7 @@
}
// build x.go, creating x
- defer os.Remove(bin)
+ p.bin = bin // to be removed by p.end
dir, file := filepath.Split(src)
args := []string{"go", "build"}
if opt != nil && opt.Race {
@@ -203,8 +204,11 @@
}
// end sends an "end" message to the client, containing the process id and the
-// given error value.
+// given error value. It also removes the binary.
func (p *process) end(err error) {
+ if p.bin != "" {
+ defer os.Remove(p.bin)
+ }
m := &Message{Id: p.id, Kind: "end"}
if err != nil {
m.Body = err.Error()