Skip to content

Commit

Permalink
cmd/go: clean paths before checking same directory
Browse files Browse the repository at this point in the history
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: c7c4905
GitHub-Pull-Request: #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>
  • Loading branch information
Gerrard-YNWA authored and Bryan C. Mills committed Sep 16, 2021
1 parent e7dbe39 commit 04f5116
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
5 changes: 1 addition & 4 deletions src/cmd/go/internal/load/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 12 additions & 2 deletions src/cmd/go/testdata/script/run_dirs.txt
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 04f5116

Please sign in to comment.