diff options
author | gerrard <gyc_ssdut@163.com> | 2021-09-16 07:10:58 +0000 |
---|---|---|
committer | Bryan C. Mills <bcmills@google.com> | 2021-09-16 14:25:50 +0000 |
commit | 04f5116c987082a834a29e81c81ece8537d87219 (patch) | |
tree | 0dc046bd42970941a68eb22c42c6945fc98be96b | |
parent | e7dbe3908e17ec77851161e6cb98c7161823aa0d (diff) | |
download | go-04f5116c987082a834a29e81c81ece8537d87219.tar.gz go-04f5116c987082a834a29e81c81ece8537d87219.zip |
cmd/go: clean paths before checking same directory
Replace `filepath.Split` with `filepath.Dir`. Clean paths before checking whether command line files are in same directory.
Fixes #47392
Change-Id: I259c3024e7670e78833622b02af4710bc4b68b31
GitHub-Last-Rev: c7c4905bb9c62737e95a4663813f076ee540046b
GitHub-Pull-Request: golang/go#47412
Reviewed-on: https://go-review.googlesource.com/c/go/+/337629
Trust: Bryan C. Mills <bcmills@google.com>
Trust: Cherry Mui <cherryyz@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
-rw-r--r-- | src/cmd/go/internal/load/pkg.go | 5 | ||||
-rw-r--r-- | src/cmd/go/testdata/script/run_dirs.txt | 14 |
2 files changed, 13 insertions, 6 deletions
diff --git a/src/cmd/go/internal/load/pkg.go b/src/cmd/go/internal/load/pkg.go index f0613a4c0a..4013330bc4 100644 --- a/src/cmd/go/internal/load/pkg.go +++ b/src/cmd/go/internal/load/pkg.go @@ -2674,10 +2674,7 @@ func GoFilesPackage(ctx context.Context, opts PackageOpts, gofiles []string) *Pa if fi.IsDir() { base.Fatalf("%s is a directory, should be a Go file", file) } - dir1, _ := filepath.Split(file) - if dir1 == "" { - dir1 = "./" - } + dir1 := filepath.Dir(file) if dir == "" { dir = dir1 } else if dir != dir1 { diff --git a/src/cmd/go/testdata/script/run_dirs.txt b/src/cmd/go/testdata/script/run_dirs.txt index 538a6ac6f3..bd5cfbe3fb 100644 --- a/src/cmd/go/testdata/script/run_dirs.txt +++ b/src/cmd/go/testdata/script/run_dirs.txt @@ -1,11 +1,21 @@ cd rundir ! go run x.go sub/sub.go -stderr 'named files must all be in one directory; have ./ and sub/' +stderr 'named files must all be in one directory; have . and sub' ! go run sub/sub.go x.go -stderr 'named files must all be in one directory; have sub/ and ./' +stderr 'named files must all be in one directory; have sub and .' + +cd ../ +go run rundir/foo.go ./rundir/bar.go +stderr 'hello world' -- rundir/sub/sub.go -- package main -- rundir/x.go -- package main +-- rundir/foo.go -- +package main +func main() { println(msg) } +-- rundir/bar.go -- +package main +const msg = "hello world" |