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: improve handling of symlinked module root for go mod (tidy)
#45609
Comments
/cc @bcmills @jayconrod @matloob It might be worth adding a friendlier error message to this scenario, and not emptying out the go.mod and go.sum files. |
Either option would be fine with me; out of curiosity (I tried to find the back story on "ignoring the symlinks"); what problems could occur if (in this specific scenario) the symlink would not be ignored? Also happy to open a pull request if there's consensus on the approach. |
This is probably a fencepost error somewhere in the FWIW, one reason we ignore symlinks in general is because if you commit a change in a repository containing a symlink, that symlink can't be reliably reproduced in the module cache. (Not all filesystems support symlinks, and not all symlinks are repo-relative.) |
Ah, yes, that makes sense (symlinks can be a bit of a PITA) So from the above;
|
Exactly. I think we should go for the “nicer” fix — unlike for nested packages, I don't see a compelling reason to disallow symlinks at the module root. |
Yup; nicer fixes are always good. Having a quick look at the link I included in my report; warning is coming from here; go/src/cmd/go/internal/modload/search.go Lines 88 to 95 in 954879d
I see a go/src/cmd/go/internal/modload/search.go Line 135 in 954879d
Which (20 second glance) looks to be the path to the module root; go/src/cmd/go/internal/modload/init.go Lines 299 to 301 in 4d56576
Looks like it's using a variable to keep that, so repeatedly using it inside the walkFn should (at a glance) likely be ok. |
Would love to see this fixed - I just wasted half an hour on it :( |
Just ran into this today when trying to do exactly what issue OP is doing - a "workspaces" directory with multiple symlinked projects I'm integrating. Would love to see this fixed too :) |
@ebauman, it is possible that this is fixed by https://go.dev/cl/463179. Could you try using a |
I would love to see this fixed too. I knew about the problem but because I encounter it so infrequently I spent a good 10 minutes this morning refreshing my memory. If nothing else I believe that a better error message is warranted. |
I've just tested and this fix does appear to work. |
Thanks! I'm going to mark this as tentatively fixed for Go 1.21, but please do let me know if you run into this failure mode at Go 1.21 or higher. |
Thanks all! Sorry, been too busy to catch up on all of these (or to open a PR), but understanding from the above, it's fixed (happy!) |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
For easy navigation between projects, I have a "jump" directory on my machine,
in which I keep symlinks to frequently used projects.
go mod tidy
ignoressymlinks (and warns about ignoring them), which is generally ok, but in situations
where the whole module is detected to be in a "symlinked" path, it can be more
disruptive.
To reproduce this situation (you can run this inside a container to not clutter
up your host);
have a Go project on your machine
Create a "projects" directory with a symlink to the project
mkdir -p /projects \ && ln -s /go/src/github.com/moby/spdystream/ /projects/spdystream
Navigate to the project using the symlink
cd /projects/spdystream
Notice that
pwd
shows the path of the symlinkpwd /projects/spdystream
(This is expected, and could be avoided by using
cd -P
instead ofcd
)Run
go mod tidy
(usually, this would be after updatinggo.mod
to update some dependencies)go mod tidy warning: ignoring symlink /projects/spdystream go: warning: "all" matched no packages
Find out that all dependencies were removed from
go.mod
, andgo.sum
tobe emptiedWhile it's generally ok to ignore symlinks within the project/module (there must be reasons for that), it's somewhat disruptive in this situation; especially in situations where you just edited
go.mod
, and then see your changes being wiped.What did you expect to see?
What I expected to see for step
5.
, isgo mod (tidy)
to either:/go/src/github.com/moby/spdystream/
and resolve modules from inside that contextgo mod tidy
to produce an error instead of a warning, and terminate before modifyinggo.mod
andgo.sum
What did you see instead?
All dependencies removed from
go.mod
, andgo.sum
emptiedThe text was updated successfully, but these errors were encountered: