mirror of
https://github.com/golang/go
synced 2024-11-22 01:44:40 -07:00
go/build: fixes for windows paths
R=golang-dev, mattn.jp, adg CC=golang-dev https://golang.org/cl/4746047
This commit is contained in:
parent
98f5fc5e86
commit
42effdf096
@ -10,7 +10,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Path is a validated list of Trees derived from $GOROOT and $GOPATH at init.
|
// 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 {
|
for _, t := range Path {
|
||||||
tpath := t.SrcDir() + string(filepath.Separator)
|
tpath := t.SrcDir() + string(filepath.Separator)
|
||||||
if !strings.HasPrefix(path, tpath) {
|
if !filepath.HasPrefix(path, tpath) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
tree = t
|
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 . ..)
|
// 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 {
|
func isLocalPath(s string) bool {
|
||||||
const sep = string(filepath.Separator)
|
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 (
|
var (
|
||||||
|
@ -38,7 +38,7 @@ const (
|
|||||||
// Getting Dot-Dot right,''
|
// Getting Dot-Dot right,''
|
||||||
// http://plan9.bell-labs.com/sys/doc/lexnames.html
|
// http://plan9.bell-labs.com/sys/doc/lexnames.html
|
||||||
func Clean(path string) string {
|
func Clean(path string) string {
|
||||||
vol := volumeName(path)
|
vol := VolumeName(path)
|
||||||
path = path[len(vol):]
|
path = path[len(vol):]
|
||||||
if path == "" {
|
if path == "" {
|
||||||
return vol + "."
|
return vol + "."
|
||||||
|
@ -11,8 +11,13 @@ func IsAbs(path string) bool {
|
|||||||
return strings.HasPrefix(path, "/") || strings.HasPrefix(path, "#")
|
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
|
// It returns "" elsewhere
|
||||||
func volumeName(path string) string {
|
func VolumeName(path string) string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HasPrefix tests whether the path p begins with prefix.
|
||||||
|
func HasPrefix(p, prefix string) bool {
|
||||||
|
return strings.HasPrefix(p, prefix)
|
||||||
|
}
|
||||||
|
@ -11,8 +11,13 @@ func IsAbs(path string) bool {
|
|||||||
return strings.HasPrefix(path, "/")
|
return strings.HasPrefix(path, "/")
|
||||||
}
|
}
|
||||||
|
|
||||||
// volumeName returns the leading volume name on Windows.
|
// VolumeName returns the leading volume name on Windows.
|
||||||
// It returns "" elsewhere.
|
// It returns "" elsewhere.
|
||||||
func volumeName(path string) string {
|
func VolumeName(path string) string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HasPrefix tests whether the path p begins with prefix.
|
||||||
|
func HasPrefix(p, prefix string) bool {
|
||||||
|
return strings.HasPrefix(p, prefix)
|
||||||
|
}
|
||||||
|
@ -4,9 +4,11 @@
|
|||||||
|
|
||||||
package filepath
|
package filepath
|
||||||
|
|
||||||
|
import "strings"
|
||||||
|
|
||||||
// IsAbs returns true if the path is absolute.
|
// IsAbs returns true if the path is absolute.
|
||||||
func IsAbs(path string) (b bool) {
|
func IsAbs(path string) (b bool) {
|
||||||
v := volumeName(path)
|
v := VolumeName(path)
|
||||||
if v == "" {
|
if v == "" {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -17,9 +19,10 @@ func IsAbs(path string) (b bool) {
|
|||||||
return path[0] == '/' || path[0] == '\\'
|
return path[0] == '/' || path[0] == '\\'
|
||||||
}
|
}
|
||||||
|
|
||||||
// volumeName return leading volume name.
|
// VolumeName returns leading volume name.
|
||||||
// If given "C:\foo\bar", return "C:" on windows.
|
// Given "C:\foo\bar" it returns "C:" under windows.
|
||||||
func volumeName(path string) (v string) {
|
// On other platforms it returns "".
|
||||||
|
func VolumeName(path string) (v string) {
|
||||||
if len(path) < 2 {
|
if len(path) < 2 {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
@ -32,3 +35,12 @@ func volumeName(path string) (v string) {
|
|||||||
}
|
}
|
||||||
return ""
|
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))
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user