// If so, InDir returns an equivalent path relative to dir.
// If not, InDir returns an empty string.
// 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 {
if rel := inDirLex(path, dir); rel != "" {
return rel
"cmd/go/internal/cfg"
"cmd/go/internal/load"
"cmd/go/internal/lockedfile"
+ "cmd/go/internal/search"
"cmd/go/internal/str"
"cmd/go/internal/trace"
"cmd/go/internal/work"
if !filepath.IsAbs(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.
break
}
if !filepath.IsAbs(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.
break
}
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 {
h := cache.NewHash("getenv")
v, ok := os.LookupEnv(name)