mirror of
https://github.com/golang/go
synced 2024-11-17 07:04:44 -07:00
cmd/go: evaluate root symlink in matchPackages
This fixes checks for crossing module boundaries when the root of the module is a symlink. We're comparing paths by string, so we need to follow the symlink to get the proper path to compare. Change-Id: Idf5f0dd5c49bcae5fffb5372e99a7fab89169a9d Reviewed-on: https://go-review.googlesource.com/c/go/+/380057 Trust: Michael Matloob <matloob@golang.org> Run-TryBot: Michael Matloob <matloob@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
parent
9eba5ff521
commit
35b0db7607
@ -54,6 +54,11 @@ func matchPackages(ctx context.Context, m *search.Match, tags map[string]bool, f
|
||||
)
|
||||
|
||||
walkPkgs := func(root, importPathRoot string, prune pruning) {
|
||||
// Follow root if it's a symlink so path == root comparisons don't
|
||||
// spuriously fail when root is a symlink and it points to path.
|
||||
if r, err := filepath.EvalSymlinks(root); err == nil {
|
||||
root = r
|
||||
}
|
||||
root = filepath.Clean(root)
|
||||
err := fsys.Walk(root, func(path string, fi fs.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
|
20
src/cmd/go/testdata/script/work_root_is_symlink.txt
vendored
Normal file
20
src/cmd/go/testdata/script/work_root_is_symlink.txt
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
# Test that cmd/go follows the symlink and properly determines
|
||||
# the module boundary when the working directory is a symlink.
|
||||
|
||||
[!symlink] skip
|
||||
|
||||
symlink worksym -> workspace
|
||||
cd worksym
|
||||
go list all
|
||||
stdout example.com/workspace
|
||||
|
||||
-- workspace/go.work --
|
||||
go 1.18
|
||||
|
||||
use .
|
||||
-- workspace/go.mod --
|
||||
module example.com/workspace
|
||||
|
||||
go 1.18
|
||||
-- workspace/pkg.go --
|
||||
package workspace
|
Loading…
Reference in New Issue
Block a user