Skip to content

Commit

Permalink
vendor/cmd/go/internal/web2: fix location of netrc
Browse files Browse the repository at this point in the history
Windows will use the filename "_netrc" while all other OS's use ".netrc".

user.Current().HomeDir will be used for the directory for all OS's.

Fixes golang/go#24606

Change-Id: I8182b161c4d1e6a348a568975240131b033215b5
Reviewed-on: https://go-review.googlesource.com/103866
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
  • Loading branch information
JoshVarga authored and bradfitz committed Apr 3, 2018
1 parent 76421de commit e89a351
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions vendor/cmd/go/internal/web2/web.go
Expand Up @@ -15,6 +15,7 @@ import (
"net/http"
"os"
"path/filepath"
"runtime"
"runtime/debug"
"strings"
"sync"
Expand Down Expand Up @@ -70,8 +71,18 @@ func havePassword(machine string) bool {
return false
}

func netrcPath() string {
switch runtime.GOOS {
case "windows":
return filepath.Join(os.Getenv("USERPROFILE"), "_netrc")
case "plan9":
filepath.Join(os.Getenv("home"), ".netrc")
}
return filepath.Join(os.Getenv("HOME"), ".netrc")
}

func readNetrc() {
data, err := ioutil.ReadFile(filepath.Join(os.Getenv("HOME"), ".netrc"))
data, err := ioutil.ReadFile(netrcPath())
if err != nil {
return
}
Expand Down Expand Up @@ -277,7 +288,7 @@ create a Personal Access Token. The token only needs "public_repo"
scope, but you can add "repo" if you want to access private
repositories too.
Add the token to your $HOME/.netrc:
Add the token to your $HOME/.netrc (%USERPROFILE%\_netrc on Windows):
machine api.github.com login YOU password TOKEN
Expand Down

0 comments on commit e89a351

Please sign in to comment.