aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShenghou Ma <minux.ma@gmail.com>2013-10-14 00:18:46 -0400
committerShenghou Ma <minux.ma@gmail.com>2013-10-14 00:18:46 -0400
commit89ebc28b587228c6ce90b78db33925e19aeba7d5 (patch)
tree0998eaa057f1cc7eee700c58f0fbb84b479c0ad3
parent26f43a089e9d77cdb8c7c7f2c600631283de91f2 (diff)
downloadgo-89ebc28b587228c6ce90b78db33925e19aeba7d5.tar.gz
go-89ebc28b587228c6ce90b78db33925e19aeba7d5.zip
cmd/api: make it work even when cgo is disabled
make use of $USER or %USERNAME% to determine the current user. Fixes #6578. R=golang-dev, bradfitz, alex.brainman CC=golang-dev https://golang.org/cl/14649043
-rw-r--r--src/cmd/api/run.go14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/cmd/api/run.go b/src/cmd/api/run.go
index f7c590bbe1..ffa2d61bf3 100644
--- a/src/cmd/api/run.go
+++ b/src/cmd/api/run.go
@@ -93,13 +93,21 @@ func file(s ...string) string {
func prepGoPath() string {
const tempBase = "go.tools.TMP"
+ username := ""
u, err := user.Current()
- if err != nil {
- log.Fatalf("Error getting current user: %v", err)
+ if err == nil {
+ username = u.Username
+ } else {
+ // Only need to handle Unix here, as Windows's os/user uses
+ // native syscall and should work fine without cgo.
+ username = os.Getenv("USER")
+ if username == "" {
+ log.Fatalf("Error getting current user: %v", err)
+ }
}
// The GOPATH we'll return
- gopath := filepath.Join(os.TempDir(), "gopath-api-"+cleanUsername(u.Username), goToolsVersion)
+ gopath := filepath.Join(os.TempDir(), "gopath-api-"+cleanUsername(username), goToolsVersion)
// cloneDir is where we run "hg clone".
cloneDir := filepath.Join(gopath, "src", "code.google.com", "p")