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

Closed
tedu opened this issue Feb 20, 2019 · 5 comments
Closed

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

tedu opened this issue Feb 20, 2019 · 5 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@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 the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label 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
@gopherbot
Copy link

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

@bcmills
Copy link
Contributor

bcmills commented Mar 4, 2019

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

@tedu
Copy link
Author

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
@bcmills
Copy link
Contributor

bcmills commented Dec 21, 2020

#32725 is technically a duplicate of this issue, but that copy currently has more detail so I'm going to mark them the other way 'round.

@bcmills
Copy link
Contributor

bcmills commented Dec 21, 2020

Duplicate of #32725.

@bcmills bcmills closed this as completed Dec 21, 2020
@golang golang locked and limited conversation to collaborators Dec 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants