1
0
mirror of https://github.com/golang/go synced 2024-09-29 14:24:32 -06:00

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: c7c4905bb9
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>
This commit is contained in:
gerrard 2021-09-16 07:10:58 +00:00 committed by Bryan C. Mills
parent e7dbe3908e
commit 04f5116c98
2 changed files with 13 additions and 6 deletions

View File

@ -2674,10 +2674,7 @@ func GoFilesPackage(ctx context.Context, opts PackageOpts, gofiles []string) *Pa
if fi.IsDir() { if fi.IsDir() {
base.Fatalf("%s is a directory, should be a Go file", file) base.Fatalf("%s is a directory, should be a Go file", file)
} }
dir1, _ := filepath.Split(file) dir1 := filepath.Dir(file)
if dir1 == "" {
dir1 = "./"
}
if dir == "" { if dir == "" {
dir = dir1 dir = dir1
} else if dir != dir1 { } else if dir != dir1 {

View File

@ -1,11 +1,21 @@
cd rundir cd rundir
! go run x.go sub/sub.go ! 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 ! 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 -- -- rundir/sub/sub.go --
package main package main
-- rundir/x.go -- -- rundir/x.go --
package main package main
-- rundir/foo.go --
package main
func main() { println(msg) }
-- rundir/bar.go --
package main
const msg = "hello world"