1
0
mirror of https://github.com/golang/go synced 2024-11-26 13:08:08 -07:00

cmd/go: resolve TODO by replacing InDir() function

Change-Id: Idf886bbc4e66c9ee2a41c90034075301e0a21a58
Reviewed-on: https://go-review.googlesource.com/c/go/+/271909
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Jay Conrod <jayconrod@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Jay Conrod <jayconrod@google.com>
This commit is contained in:
Andy Pan 2020-11-21 15:27:00 +08:00 committed by Jay Conrod
parent 5e94fe9316
commit c7f596f919
2 changed files with 3 additions and 15 deletions

View File

@ -571,7 +571,6 @@ func IsRelativePath(pattern string) bool {
// If so, InDir returns an equivalent path relative to dir. // If so, InDir returns an equivalent path relative to dir.
// If not, InDir returns an empty string. // If not, InDir returns an empty string.
// InDir makes some effort to succeed even in the presence of symbolic links. // InDir makes some effort to succeed even in the presence of symbolic links.
// TODO(rsc): Replace internal/test.inDir with a call to this function for Go 1.12.
func InDir(path, dir string) string { func InDir(path, dir string) string {
if rel := inDirLex(path, dir); rel != "" { if rel := inDirLex(path, dir); rel != "" {
return rel return rel

View File

@ -29,6 +29,7 @@ import (
"cmd/go/internal/cfg" "cmd/go/internal/cfg"
"cmd/go/internal/load" "cmd/go/internal/load"
"cmd/go/internal/lockedfile" "cmd/go/internal/lockedfile"
"cmd/go/internal/search"
"cmd/go/internal/str" "cmd/go/internal/str"
"cmd/go/internal/trace" "cmd/go/internal/trace"
"cmd/go/internal/work" "cmd/go/internal/work"
@ -1499,7 +1500,7 @@ func computeTestInputsID(a *work.Action, testlog []byte) (cache.ActionID, error)
if !filepath.IsAbs(name) { if !filepath.IsAbs(name) {
name = filepath.Join(pwd, name) name = filepath.Join(pwd, name)
} }
if a.Package.Root == "" || !inDir(name, a.Package.Root) { if a.Package.Root == "" || search.InDir(name, a.Package.Root) == "" {
// Do not recheck files outside the module, GOPATH, or GOROOT root. // Do not recheck files outside the module, GOPATH, or GOROOT root.
break break
} }
@ -1508,7 +1509,7 @@ func computeTestInputsID(a *work.Action, testlog []byte) (cache.ActionID, error)
if !filepath.IsAbs(name) { if !filepath.IsAbs(name) {
name = filepath.Join(pwd, name) name = filepath.Join(pwd, name)
} }
if a.Package.Root == "" || !inDir(name, a.Package.Root) { if a.Package.Root == "" || search.InDir(name, a.Package.Root) == "" {
// Do not recheck files outside the module, GOPATH, or GOROOT root. // Do not recheck files outside the module, GOPATH, or GOROOT root.
break break
} }
@ -1526,18 +1527,6 @@ func computeTestInputsID(a *work.Action, testlog []byte) (cache.ActionID, error)
return sum, nil return sum, nil
} }
func inDir(path, dir string) bool {
if str.HasFilePathPrefix(path, dir) {
return true
}
xpath, err1 := filepath.EvalSymlinks(path)
xdir, err2 := filepath.EvalSymlinks(dir)
if err1 == nil && err2 == nil && str.HasFilePathPrefix(xpath, xdir) {
return true
}
return false
}
func hashGetenv(name string) cache.ActionID { func hashGetenv(name string) cache.ActionID {
h := cache.NewHash("getenv") h := cache.NewHash("getenv")
v, ok := os.LookupEnv(name) v, ok := os.LookupEnv(name)