]> Cypherpunks repositories - gostls13.git/commitdiff
misc/android: fix detection of GOROOT tests
authorElias Naur <mail@eliasnaur.com>
Tue, 12 Mar 2019 15:21:43 +0000 (16:21 +0100)
committerElias Naur <mail@eliasnaur.com>
Tue, 12 Mar 2019 15:47:18 +0000 (15:47 +0000)
strings.HasPrefix is not good enough to determine whether a path
is a subdirectory of another because it does not respect path
boundaries. filepath.Rel is good eonugh as long as we filter out results
that use parent directories, "..".

Hopefully fix the android emulator builders on the subrepositories.

Change-Id: I17ee7e0028c0b0b26a6c5f67629f53c9a660c6e5
Reviewed-on: https://go-review.googlesource.com/c/go/+/167117
Run-TryBot: Elias Naur <mail@eliasnaur.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

misc/android/go_android_exec.go

index a662d2894462d5625f12e1cdb39d253a604e0593..ee3f16ae3d73852b48dbc5658cbc1634636930c0 100644 (file)
@@ -196,12 +196,10 @@ func subdir() (pkgpath string, underGoRoot bool, err error) {
        if err != nil {
                return "", false, err
        }
-       if strings.HasPrefix(cwd, goroot) {
-               subdir, err := filepath.Rel(goroot, cwd)
-               if err != nil {
-                       return "", false, err
+       if subdir, err := filepath.Rel(goroot, cwd); err == nil {
+               if !strings.Contains(subdir, "..") {
+                       return subdir, true, nil
                }
-               return subdir, true, nil
        }
 
        for _, p := range filepath.SplitList(build.Default.GOPATH) {
@@ -209,12 +207,10 @@ func subdir() (pkgpath string, underGoRoot bool, err error) {
                if err != nil {
                        return "", false, err
                }
-               if !strings.HasPrefix(cwd, pabs) {
-                       continue
-               }
-               subdir, err := filepath.Rel(pabs, cwd)
-               if err == nil {
-                       return subdir, false, nil
+               if subdir, err := filepath.Rel(pabs, cwd); err == nil {
+                       if !strings.Contains(subdir, "..") {
+                               return subdir, false, nil
+                       }
                }
        }
        return "", false, fmt.Errorf("the current path %q is not in either GOROOT(%q) or GOPATH(%q)",