]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/api: make api check directory per-user
authorRobert Daniel Kortschak <dan.kortschak@adelaide.edu.au>
Wed, 11 Sep 2013 00:50:56 +0000 (10:50 +1000)
committerAlex Brainman <alex.brainman@gmail.com>
Wed, 11 Sep 2013 00:50:56 +0000 (10:50 +1000)
Fixes #6353.

R=golang-dev, bradfitz, alex.brainman
CC=golang-dev
https://golang.org/cl/13652043

src/cmd/api/run.go

index 067be4eb05d0ae952f6d6472a475d1a4dbe62ccf..9ecd03a60730287dc738a7e3bdfb48d1d972229d 100644 (file)
@@ -19,6 +19,7 @@ import (
        "net/http"
        "os"
        "os/exec"
+       "os/user"
        "path/filepath"
        "strconv"
        "strings"
@@ -99,8 +100,13 @@ func forceAPICheck() bool {
 func prepGoPath() string {
        const tempBase = "go.tools.TMP"
 
+       u, err := user.Current()
+       if err != nil {
+               log.Fatalf("Error getting current user: %v", err)
+       }
+
        // The GOPATH we'll return
-       gopath := filepath.Join(os.TempDir(), "gopath-api", goToolsVersion)
+       gopath := filepath.Join(os.TempDir(), "gopath-api-"+cleanUsername(u.Username), goToolsVersion)
 
        // cloneDir is where we run "hg clone".
        cloneDir := filepath.Join(gopath, "src", "code.google.com", "p")
@@ -140,6 +146,18 @@ func prepGoPath() string {
        return gopath
 }
 
+func cleanUsername(n string) string {
+       b := make([]rune, len(n))
+       for i, r := range n {
+               if r == '\\' || r == '/' || r == ':' {
+                       b[i] = '_'
+               } else {
+                       b[i] = r
+               }
+       }
+       return string(b)
+}
+
 func goToolsCheckoutGood(dir string) bool {
        if _, err := os.Stat(dir); err != nil {
                return false