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 not traversing symlinks #17451

Closed
krisnova opened this issue Oct 15, 2016 · 4 comments
Closed

cmd/go: Go not traversing symlinks #17451

krisnova opened this issue Oct 15, 2016 · 4 comments
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@krisnova
Copy link

krisnova commented Oct 15, 2016

V 1.6.2 Darwin/AMD64

# My project lives here
cd ~/myproject

# My $GOPATH is ~/gopath
echo $GOPATH
/Users/kris/gopath

# Symlink my project into $GOPATH
ln -s ~/myproject $GOPATH/src/myproject
go install $GOPATH/src/myproject/...

#This error message
warning: "/Users/kris/gopath/myproject/..." matched no packages

I would expect go to respect and follow the symlink and traverse the path as it would with a hardlink.

@as
Copy link
Contributor

as commented Oct 16, 2016

The go command uses filepath.Walk to match packages, and filepath.Walk does not follow symbolic links at this time.

Changing this means either modifying filepath.Walk or creating a custom walk that resolves symbolic links.

I would not encourage the first option on due to Compatibility guidelines. I rely on filepath.Walk behavior not to follow symlinks, and on many Linux systems I use this would cause circular non-terminating traversals.

$GOROOT/src/cmd/go/main.go:560,561:        fmt.Fprintf(os.Stderr, "warning: %q matched no packages\n", pattern)
$GOROOT/src/cmd/go/main.go:565,566:        func matchPackages(pattern string) []string {
$GOROOT/src/cmd/go/main.go:590,591:            filepath.Walk(root, func(path string, fi os.FileInfo, err error) error {

go doc filepath.Walk
func Walk(root string, walkFn WalkFunc) error
    Walk walks the file tree rooted at root, calling walkFn for each file or
    directory in the tree, including root. All errors that arise visiting files
    and directories are filtered by walkFn. The files are walked in lexical
    order, which makes the output deterministic but means that for very large
    directories Walk can be inefficient. Walk does not follow symbolic links.

@mikioh mikioh changed the title Go not traversing symlinks cmd/go: Go not traversing symlinks Oct 16, 2016
@krisnova
Copy link
Author

Ah thanks for the response @as - this makes a lot more sense now. I would say it's safe to set this is a nuisance more than anything else. But I still am curious if the issue needs to be addressed?

Is the ability to follow symlinks in this context something we would like to see in a later version of go?

@as
Copy link
Contributor

as commented Oct 16, 2016

There was a proposal to add this feature in May, but it was declined. The reason is that symlinks introduce too much complexity and aren't worth their trouble.

I agree with the reason. The symlinks on my Linux systems were created by the distribution builders and I personally avoid them. If you're unable to use hard links, maybe 'mount -o bind' can solve your problem by approximating a namespace in Linux.

@quentinmit quentinmit added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Oct 17, 2016
@quentinmit quentinmit added this to the Go1.8Maybe milestone Oct 17, 2016
@rsc
Copy link
Contributor

rsc commented Oct 20, 2016

Like in #15507, we're not going to attempt this. It creates too many other issues. You could instead symlink ~/myproject -> your GOPATH. Apologies.

@rsc rsc closed this as completed Oct 20, 2016
majewsky added a commit to sapcc/limes that referenced this issue Aug 2, 2017
This reverts commit 6c1fd2c,
because it breaks normal operation due to
<golang/go#17451>.
@golang golang locked and limited conversation to collaborators Oct 20, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

5 participants