diff options
author | Robert Daniel Kortschak <dan.kortschak@adelaide.edu.au> | 2013-09-11 10:50:56 +1000 |
---|---|---|
committer | Robert Daniel Kortschak <dan.kortschak@adelaide.edu.au> | 2013-09-11 10:50:56 +1000 |
commit | 313d992c51c85f1e8b420dfaee84fb54420de3d6 (patch) | |
tree | b18d6025e8c4fc3fe365ff7cfe2d2590bc715e89 /src/cmd/api | |
parent | c5776987de9b3db82a10594604fed70d2241f1b4 (diff) | |
download | go-313d992c51c85f1e8b420dfaee84fb54420de3d6.tar.gz |
cmd/api: make api check directory per-user
Fixes issue 6353.
R=golang-dev, bradfitz, alex.brainman
CC=golang-dev
https://codereview.appspot.com/13652043
Committer: Alex Brainman <alex.brainman@gmail.com>
Diffstat (limited to 'src/cmd/api')
-rw-r--r-- | src/cmd/api/run.go | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/cmd/api/run.go b/src/cmd/api/run.go index 067be4eb0..9ecd03a60 100644 --- a/src/cmd/api/run.go +++ b/src/cmd/api/run.go @@ -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 |