Skip to content

Commit 4a1d39b

Browse files
author
Bryan C. Mills
committed
[release-branch.go1.12] cmd/go/internal/imports: use the full path to resolve symlinks
info.Name returns a name relative to the directory, so we need to prefix that directory in the Stat call. (This was missed in CL 141097 due to the fact that the test only happened to check symlinks in the current directory.) This allows the misc/ tests to work in module mode on platforms that support symlinks. Updates #30228 Updates #28107 Fixes #31763 Change-Id: Ie31836382df0cbd7d203b7a8b637c4743d68b6f3 Reviewed-on: https://go-review.googlesource.com/c/163517 Run-TryBot: Bryan C. Mills <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Jay Conrod <[email protected]> Reviewed-on: https://go-review.googlesource.com/c/go/+/175441 Reviewed-by: Andrew Bonventre <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent e02d818 commit 4a1d39b

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

src/cmd/go/internal/imports/scan.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func ScanDir(dir string, tags map[string]bool) ([]string, []string, error) {
2626
// If the directory entry is a symlink, stat it to obtain the info for the
2727
// link target instead of the link itself.
2828
if info.Mode()&os.ModeSymlink != 0 {
29-
info, err = os.Stat(name)
29+
info, err = os.Stat(filepath.Join(dir, name))
3030
if err != nil {
3131
continue // Ignore broken symlinks.
3232
}

src/cmd/go/testdata/script/mod_symlink.txt

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,31 @@ env GO111MODULE=on
22
[!symlink] skip
33

44
# 'go list' should resolve modules of imported packages.
5-
go list -deps -f '{{.Module}}'
5+
go list -deps -f '{{.Module}}' .
66
stdout golang.org/x/text
77

8-
# They should continue to resolve if the importing file is a symlink.
8+
go list -deps -f '{{.Module}}' ./subpkg
9+
stdout golang.org/x/text
10+
11+
# Create a copy of the module using symlinks in src/links.
912
mkdir links
13+
symlink links/go.mod -> $GOPATH/src/go.mod
14+
symlink links/issue.go -> $GOPATH/src/issue.go
15+
mkdir links/subpkg
16+
symlink links/subpkg/issue.go -> $GOPATH/src/subpkg/issue.go
17+
18+
# We should see the copy as a valid module root.
1019
cd links
11-
symlink go.mod -> ../go.mod
12-
symlink issue.go -> ../issue.go
20+
go env GOMOD
21+
stdout links[/\\]go.mod
22+
go list -m
23+
stdout golang.org/issue/28107
1324

14-
go list -deps -f '{{.Module}}'
25+
# The symlink-based copy should contain the same packages
26+
# and have the same dependencies as the original.
27+
go list -deps -f '{{.Module}}' .
28+
stdout golang.org/x/text
29+
go list -deps -f '{{.Module}}' ./subpkg
1530
stdout golang.org/x/text
1631

1732
-- go.mod --
@@ -21,3 +36,7 @@ module golang.org/issue/28107
2136
package issue
2237

2338
import _ "golang.org/x/text/language"
39+
-- subpkg/issue.go --
40+
package issue
41+
42+
import _ "golang.org/x/text/language"

0 commit comments

Comments
 (0)