Skip to content

cmd/go: work use failing with symlinks in the path #68383

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

Closed
dgeorgievski opened this issue Jul 11, 2024 · 4 comments
Closed

cmd/go: work use failing with symlinks in the path #68383

dgeorgievski opened this issue Jul 11, 2024 · 4 comments
Assignees
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@dgeorgievski
Copy link

Go version

go version go1.22.0 linux/amd64

Output of go env in your module/workspace:

GO111MODULE='on'
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/ubuntu/workspace/.cache/go-build'
GOENV='/home/ubuntu/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/ubuntu/workspace/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/ubuntu/workspace/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.0'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/ubuntu/workspace/Projects/eval/go/patching/go.mod'
GOWORK='/home/ubuntu/workspace/Projects/eval/go/patching/go.work'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1646219358=/tmp/go-build -gno-record-gcc-switches'

What did you do?

I was reviewing the suggestions for local patching in this article
https://eli.thegreenplace.net/2024/locally-patching-dependencies-in-go/

Go workspaces was one of the suggestions. I tried the code in path on the local file system accessed through a symlink named Projects and tried to invoke go work use command.

# symlink: Projects -> workspace/Projects/
 $ cd Projects/eval/go/patching/
/home/ubuntu/Projects/eval/go/patching
$ ls -l
total 12
-rw-rw-r-- 1 ubuntu ubuntu  69 Jul 11 14:45 go.mod
-rw-rw-r-- 1 ubuntu ubuntu 167 Jul 11 14:38 go.sum
-rw-rw-r-- 1 ubuntu ubuntu 316 Jul 11 14:38 main.go

$ echo $DEP
/home/ubuntu/temp/go-cmp

$ go work init
$ go work use . $DEP
go: directory ../../../../temp/go-cmp does not exist 

It looks like go work skips one level if a symlink is used

If I don't use the symlink to access the working directory everything works fine

$ cd ~/workspace/Projects/eval/go/patching/
$ go mod init 
$ go work use . $DEP
$ cat go.work
go 1.22.0

use (
        .
        /home/ubuntu/temp/go-cmp
)

What did you see happen?

go mod use fails if I use the symlink to access the working directory.

What did you expect to see?

go mod use to create go.work file and correctly refer the directories with go.mod files

@cagedmantis cagedmantis changed the title go work use failing with symlinks in the path cmd/go: work use failing with symlinks in the path Jul 11, 2024
@seankhliao seankhliao added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. GoCommand cmd/go labels Jul 13, 2024
@matloob matloob self-assigned this Jul 16, 2024
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/603136 mentions this issue: cmd/go: avoid making some paths relative in go work use

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/630276 mentions this issue: cmd/go: remove base.ShortPathConservative

gopherbot pushed a commit that referenced this issue Nov 20, 2024
This CL first removes the base.ShortPathConservative function. It had
two classes of uses. The first was in opening files where the paths end
up in error messages. In all those cases, the non-shortened paths are
used to open the files, and ShortPath is only used for the error
messages. The second is in base.RelPaths. RelPaths will now call
ShortPath for each of the paths passed in instead of calling
RelConservative and then doing the same check as ShortPath to see if the
path is shorter.

To avoid the possibility of incorrect relative paths ending up in error
messages (that might have command lines suggested for users to run), and
to avoid the possibility of incorrect relative paths appearing in the
output of base.RelPaths, base.ShortPaths always does an os.SameFile
check to make sure that the relative path its providing is actually
correct. Since this makes ShortPath slower than just manipulating paths
(because we need to stat the files), we need to be continue to enforce
that ShortPath is only called for error messages (with the exception of
base.RelPaths and its callers).

This is a simpler way of solving the problem that base.ShortPaths
intended to solve.

For #68383

Change-Id: I474f464f51a9acb2250069dea3054b55d95a4ab4
Reviewed-on: https://go-review.googlesource.com/c/go/+/630276
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Sam Thanawalla <[email protected]>
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/630280 mentions this issue: cmd/go remove base.ShortPathConservative

gopherbot pushed a commit that referenced this issue Nov 21, 2024
This CL rolls forward CL 630276, fixing the issues with the longtest builders that required the revert in CL 630317.

The change this CL makes compared to CL 630276 is adding the
shortPathErrorList function to rewrite the paths in the modfile.Errors
in a modfile.ErrorList using base.ShortPath and calling it on the error
returned from modfile.Parse.

The following is the commit message from the original change:

This CL first removes the base.ShortPathConservative function. It had
two classes of uses. The first was in opening files where the paths end
up in error messages. In all those cases, the non-shortened paths are
used to open the files, and ShortPath is only used for the error
messages. The second is in base.RelPaths. RelPaths will now call
ShortPath for each of the paths passed in instead of calling
RelConservative and then doing the same check as ShortPath to see if the
path is shorter.

To avoid the possibility of incorrect relative paths ending up in error
messages (that might have command lines suggested for users to run), and
to avoid the possibility of incorrect relative paths appearing in the
output of base.RelPaths, base.ShortPaths always does an os.SameFile
check to make sure that the relative path its providing is actually
correct. Since this makes ShortPath slower than just manipulating paths
(because we need to stat the files), we need to be continue to enforce
that ShortPath is only called for error messages (with the exception of
base.RelPaths and its callers).

This is a simpler way of solving the problem that base.ShortPaths
intended to solve.

For #68383

Change-Id: Ibcefb343535bd82999916b2282e9b512bb683433
Cq-Include-Trybots: luci.golang.try:gotip-windows-amd64-longtest,gotip-linux-amd64-longtest
Reviewed-on: https://go-review.googlesource.com/c/go/+/630280
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Sam Thanawalla <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants