Commit b34ec90e authored by Robert Daniel Kortschak's avatar Robert Daniel Kortschak Committed by Alex Brainman

cmd/api: make api check directory per-user

Fixes #6353.

R=golang-dev, bradfitz, alex.brainman
CC=golang-dev
https://golang.org/cl/13652043
parent b99fdb2a
...@@ -19,6 +19,7 @@ import ( ...@@ -19,6 +19,7 @@ import (
"net/http" "net/http"
"os" "os"
"os/exec" "os/exec"
"os/user"
"path/filepath" "path/filepath"
"strconv" "strconv"
"strings" "strings"
...@@ -99,8 +100,13 @@ func forceAPICheck() bool { ...@@ -99,8 +100,13 @@ func forceAPICheck() bool {
func prepGoPath() string { func prepGoPath() string {
const tempBase = "go.tools.TMP" 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 // 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 is where we run "hg clone".
cloneDir := filepath.Join(gopath, "src", "code.google.com", "p") cloneDir := filepath.Join(gopath, "src", "code.google.com", "p")
...@@ -140,6 +146,18 @@ func prepGoPath() string { ...@@ -140,6 +146,18 @@ func prepGoPath() string {
return gopath 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 { func goToolsCheckoutGood(dir string) bool {
if _, err := os.Stat(dir); err != nil { if _, err := os.Stat(dir); err != nil {
return false return false
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment