]> Cypherpunks repositories - gostls13.git/commitdiff
go/build: fixes for windows paths
authorAlex Brainman <alex.brainman@gmail.com>
Tue, 19 Jul 2011 04:02:23 +0000 (14:02 +1000)
committerAlex Brainman <alex.brainman@gmail.com>
Tue, 19 Jul 2011 04:02:23 +0000 (14:02 +1000)
R=golang-dev, mattn.jp, adg
CC=golang-dev
https://golang.org/cl/4746047

src/pkg/go/build/path.go
src/pkg/path/filepath/path.go
src/pkg/path/filepath/path_plan9.go
src/pkg/path/filepath/path_unix.go
src/pkg/path/filepath/path_windows.go

index e21dababd7acd4ed464cbd8d022454099e75ab06..7c120d064cb0ae1514f59ac0b6637c3a5fd9bedb 100644 (file)
@@ -10,7 +10,6 @@ import (
        "os"
        "path/filepath"
        "runtime"
-       "strings"
 )
 
 // Path is a validated list of Trees derived from $GOROOT and $GOPATH at init.
@@ -96,7 +95,7 @@ func FindTree(path string) (tree *Tree, pkg string, err os.Error) {
                }
                for _, t := range Path {
                        tpath := t.SrcDir() + string(filepath.Separator)
-                       if !strings.HasPrefix(path, tpath) {
+                       if !filepath.HasPrefix(path, tpath) {
                                continue
                        }
                        tree = t
@@ -123,9 +122,13 @@ func FindTree(path string) (tree *Tree, pkg string, err os.Error) {
 }
 
 // isLocalPath returns whether the given path is local (/foo ./foo ../foo . ..)
+// Windows paths that starts with drive letter (c:\foo c:foo) are considered local.
 func isLocalPath(s string) bool {
        const sep = string(filepath.Separator)
-       return strings.HasPrefix(s, sep) || strings.HasPrefix(s, "."+sep) || strings.HasPrefix(s, ".."+sep) || s == "." || s == ".."
+       return s == "." || s == ".." ||
+               filepath.HasPrefix(s, sep) ||
+               filepath.HasPrefix(s, "."+sep) || filepath.HasPrefix(s, ".."+sep) ||
+               filepath.VolumeName(s) != ""
 }
 
 var (
index 28ad676c252eaebcadf5f46ad935997b3e0140a5..3d5b915c1013641049ef592e9fbc5a213397f6eb 100644 (file)
@@ -38,7 +38,7 @@ const (
 // Getting Dot-Dot right,''
 // http://plan9.bell-labs.com/sys/doc/lexnames.html
 func Clean(path string) string {
-       vol := volumeName(path)
+       vol := VolumeName(path)
        path = path[len(vol):]
        if path == "" {
                return vol + "."
index 47990e0fe073783726645ee89e558c23e2f2c2de..17b873f1a9b94603c4bfc966ca809730869677ee 100644 (file)
@@ -11,8 +11,13 @@ func IsAbs(path string) bool {
        return strings.HasPrefix(path, "/") || strings.HasPrefix(path, "#")
 }
 
-// volumeName returns the leading volume name on Windows.
+// VolumeName returns the leading volume name on Windows.
 // It returns "" elsewhere
-func volumeName(path string) string {
+func VolumeName(path string) string {
        return ""
 }
+
+// HasPrefix tests whether the path p begins with prefix.
+func HasPrefix(p, prefix string) bool {
+       return strings.HasPrefix(p, prefix)
+}
index ea555fc0e129b95d99cdd2f593e81256a36c94aa..b2a4151c1a85f595141db3f1809247aba05dc418 100644 (file)
@@ -11,8 +11,13 @@ func IsAbs(path string) bool {
        return strings.HasPrefix(path, "/")
 }
 
-// volumeName returns the leading volume name on Windows.
+// VolumeName returns the leading volume name on Windows.
 // It returns "" elsewhere.
-func volumeName(path string) string {
+func VolumeName(path string) string {
        return ""
 }
+
+// HasPrefix tests whether the path p begins with prefix.
+func HasPrefix(p, prefix string) bool {
+       return strings.HasPrefix(p, prefix)
+}
index b7d18ee5a8749fe50a40847f28f51348afee57e0..2535697fd9eed8c9243020b31a974067d27707e5 100644 (file)
@@ -4,9 +4,11 @@
 
 package filepath
 
+import "strings"
+
 // IsAbs returns true if the path is absolute.
 func IsAbs(path string) (b bool) {
-       v := volumeName(path)
+       v := VolumeName(path)
        if v == "" {
                return false
        }
@@ -17,9 +19,10 @@ func IsAbs(path string) (b bool) {
        return path[0] == '/' || path[0] == '\\'
 }
 
-// volumeName return leading volume name.  
-// If given "C:\foo\bar", return "C:" on windows.
-func volumeName(path string) (v string) {
+// VolumeName returns leading volume name.  
+// Given "C:\foo\bar" it returns "C:" under windows.
+// On other platforms it returns "".
+func VolumeName(path string) (v string) {
        if len(path) < 2 {
                return ""
        }
@@ -32,3 +35,12 @@ func volumeName(path string) (v string) {
        }
        return ""
 }
+
+// HasPrefix tests whether the path p begins with prefix.
+// It ignores case while comparing.
+func HasPrefix(p, prefix string) bool {
+       if strings.HasPrefix(p, prefix) {
+               return true
+       }
+       return strings.HasPrefix(strings.ToLower(p), strings.ToLower(prefix))
+}