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 fmt doesn't work in symlinked directory #30336

Open
tedu opened this Issue Feb 20, 2019 · 3 comments

Comments

Projects
None yet
4 participants
@tedu
Copy link

tedu commented Feb 20, 2019

go version go1.11.4 openbsd/amd64

go fmt does not work when used in a symlinked directory.

I have some source buried under gopath, with symlinks for easy access.
This mostly works, but go fmt gets confused.

mkdir -p go/src/a/b/c/d/issueX
ln -s go/src/a/b/c/d/issueX
cd issueX
echo "package main" > main.go
echo "func main() {}" >> main.go

go fmt
stat ../go/src/a/b/c/d/issueX/main.go: no such file or directory
exit status 2

Something has gone wrong here with the combination of $PWD, getcwd, and path creation. go fmt has successfully found the file it wants to format, but constructs a path that doesn't work.

I found this issue about symlinks out of gopath, with a comment from rsc suggesting a symlink into gopath, which I read to mean this should work. #17451

Note that go build and go install both work fine.

Given a filename (go fmt *.go), it works. It's only "auto-finding" that screws up.

@dmitshur dmitshur changed the title go fmt doesn't work in symlinked directory cmd/go: go fmt doesn't work in symlinked directory Feb 21, 2019

@dmitshur dmitshur added this to the Go1.13 milestone Feb 21, 2019

zegl added a commit to zegl/go that referenced this issue Mar 2, 2019

cmd/go: make sure that the RelPaths always returns valid paths
When dealing with symlinks, filepath.Rel does not always return a valid path
as described in golang#30336

This change makes sure that the shorter path is not used if it isn't valid.

Fixes golang#30336
@gopherbot

This comment has been minimized.

Copy link

gopherbot commented Mar 2, 2019

Change https://golang.org/cl/164957 mentions this issue: cmd/go: make sure that the RelPaths always returns valid paths

@bcmills

This comment has been minimized.

Copy link
Member

bcmills commented Mar 4, 2019

How deep is the actual working directory in your example?
(Could this be another symptom of #30520?)

@tedu

This comment has been minimized.

Copy link
Author

tedu commented Mar 6, 2019

The example above was run from /home/tedu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.