Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: go get detects GOPATH as GOROOT if it contains GOROOT files #20057

Closed
lggomez opened this issue Apr 20, 2017 · 3 comments
Closed

cmd/go: go get detects GOPATH as GOROOT if it contains GOROOT files #20057

lggomez opened this issue Apr 20, 2017 · 3 comments

Comments

@lggomez
Copy link

lggomez commented Apr 20, 2017

go get GOROOT check is aggressive when GOPATH contains GOROOT files, specifically src/cmd/go/alldocs.go

The offending check is here

Moving the check to an else after the path equality check should solve the issue, altough I'm not sure if this file verification has a concrete reason behind it:

// Guard against people setting GOPATH=$GOROOT.
if filepath.Clean(list[0]) == filepath.Clean(cfg.GOROOT) {
	return fmt.Errorf("cannot download, $GOPATH must not be set to $GOROOT. For more details see: 'go help gopath'")
} else {
	if _, err := os.Stat(filepath.Join(list[0], "src/cmd/go/alldocs.go")); err == nil {
		return fmt.Errorf("cannot download, %s is a GOROOT, not a GOPATH. For more details see: 'go help gopath'", list[0])
	}
}

What version of Go are you using (go version)?

go version go1.8 windows/amd64

What operating system and processor architecture are you using (go env)?

GOARCH=amd64
GOBIN=
GOEXE=.exe
GOHOSTARCH=amd64
GOHOSTOS=windows
GOOS=windows

What did you do?

While I was configuring my workspaces I made the seemengly innocuous mistake of copying GOROOT files into my GOPATH folder. After that I couldn't download packages anymore

What did you expect to see?

I expected go get to install the desired package into my workspace

What did you see instead?

I get the following error:
cannot download, C:\Users\user\go is a GOROOT, not a GOPATH. For more details see: 'go help gopath'

@bradfitz
Copy link
Contributor

This is working as intended. The check exists to catch people who accidentally set their GOPATH to their GOROOT. But then you turned your GOPATH into a GOROOT by accident, and the check caught it.

Just delete those files and you're good. I don't think we need to modify cmd/go.

Let me know if I'm missing something.

@linkerlin
Copy link

@bradfitz I have the same problem. The cmd/go detect my gopath as goroot.

@lggomez
Copy link
Author

lggomez commented Apr 24, 2017

Seems good to me now that I know the rationale behind this, although I'd have preferred a distinctive error message for this case since the GOPATH and GOROOT env paths aren't equal, as the error message implies

@golang golang locked and limited conversation to collaborators Apr 24, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants