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

tedu opened this issue Feb 20, 2019 · 3 comments · May be fixed by #30533

cmd/go: go fmt doesn't work in symlinked directory #30336

tedu opened this issue Feb 20, 2019 · 3 comments · May be fixed by #30533


Copy link

@tedu 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
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
Copy link

@gopherbot gopherbot commented Mar 2, 2019

Change mentions this issue: cmd/go: make sure that the RelPaths always returns valid paths

Copy link

@bcmills bcmills commented Mar 4, 2019

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

Copy link

@tedu tedu commented Mar 6, 2019

The example above was run from /home/tedu.

@andybons andybons modified the milestones: Go1.13, Go1.14 Jul 8, 2019
@rsc rsc modified the milestones: Go1.14, Backlog Oct 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

6 participants
You can’t perform that action at this time.