diff options
| author | Yasuhiro Matsumoto <mattn.jp@gmail.com> | 2011-05-29 13:03:49 +1000 |
|---|---|---|
| committer | Alex Brainman <alex.brainman@gmail.com> | 2011-05-29 13:03:49 +1000 |
| commit | 0f4510b3707bc1b8cfbcdfeed609524d00f5c1ca (patch) | |
| tree | 5e25f25183693786906a917ca9e595c84c8baa56 /src/pkg/path/filepath | |
| parent | 505f0bb3ce55871b7c79cfcd34fa468f5cee73ef (diff) | |
| download | go-0f4510b3707bc1b8cfbcdfeed609524d00f5c1ca.tar.xz | |
os: fix os.MkdirAll with backslash path separator.
MkdirAll() need to use isSeparator().
Move primary defines of filepath.Separator/filepath.ListSeparator
to os.PathSeparator/os.PathListSeparator.
Move filepath.isSeparator() to os.IsPathSeparator().
filepath package refer them from os package.
Fixes #1831.
R=rsc, alex.brainman
CC=golang-dev
https://golang.org/cl/4535100
Diffstat (limited to 'src/pkg/path/filepath')
| -rw-r--r-- | src/pkg/path/filepath/path.go | 20 | ||||
| -rw-r--r-- | src/pkg/path/filepath/path_plan9.go | 10 | ||||
| -rw-r--r-- | src/pkg/path/filepath/path_unix.go | 10 | ||||
| -rw-r--r-- | src/pkg/path/filepath/path_windows.go | 15 |
4 files changed, 14 insertions, 41 deletions
diff --git a/src/pkg/path/filepath/path.go b/src/pkg/path/filepath/path.go index 6917218dbe..147256a1d3 100644 --- a/src/pkg/path/filepath/path.go +++ b/src/pkg/path/filepath/path.go @@ -15,6 +15,8 @@ import ( ) const ( + Separator = os.PathSeparator + ListSeparator = os.PathListSeparator SeparatorString = string(Separator) ListSeparatorString = string(ListSeparator) ) @@ -61,20 +63,20 @@ func Clean(path string) string { for r < n { switch { - case isSeparator(path[r]): + case os.IsPathSeparator(path[r]): // empty path element r++ - case path[r] == '.' && (r+1 == n || isSeparator(path[r+1])): + case path[r] == '.' && (r+1 == n || os.IsPathSeparator(path[r+1])): // . element r++ - case path[r] == '.' && path[r+1] == '.' && (r+2 == n || isSeparator(path[r+2])): + case path[r] == '.' && path[r+1] == '.' && (r+2 == n || os.IsPathSeparator(path[r+2])): // .. element: remove to last separator r += 2 switch { case w > dotdot: // can backtrack w-- - for w > dotdot && !isSeparator(buf[w]) { + for w > dotdot && !os.IsPathSeparator(buf[w]) { w-- } case !rooted: @@ -97,7 +99,7 @@ func Clean(path string) string { w++ } // copy element - for ; r < n && !isSeparator(path[r]); r++ { + for ; r < n && !os.IsPathSeparator(path[r]); r++ { buf[w] = path[r] w++ } @@ -145,7 +147,7 @@ func SplitList(path string) []string { // and file set to path. func Split(path string) (dir, file string) { i := len(path) - 1 - for i >= 0 && !isSeparator(path[i]) { + for i >= 0 && !os.IsPathSeparator(path[i]) { i-- } return path[:i+1], path[i+1:] @@ -167,7 +169,7 @@ func Join(elem ...string) string { // in the final element of path; it is empty if there is // no dot. func Ext(path string) string { - for i := len(path) - 1; i >= 0 && !isSeparator(path[i]); i-- { + for i := len(path) - 1; i >= 0 && !os.IsPathSeparator(path[i]); i-- { if path[i] == '.' { return path[i:] } @@ -339,12 +341,12 @@ func Base(path string) string { return "." } // Strip trailing slashes. - for len(path) > 0 && isSeparator(path[len(path)-1]) { + for len(path) > 0 && os.IsPathSeparator(path[len(path)-1]) { path = path[0 : len(path)-1] } // Find the last element i := len(path) - 1 - for i >= 0 && !isSeparator(path[i]) { + for i >= 0 && !os.IsPathSeparator(path[i]) { i-- } if i >= 0 { diff --git a/src/pkg/path/filepath/path_plan9.go b/src/pkg/path/filepath/path_plan9.go index e40008364c..47990e0fe0 100644 --- a/src/pkg/path/filepath/path_plan9.go +++ b/src/pkg/path/filepath/path_plan9.go @@ -6,16 +6,6 @@ package filepath import "strings" -const ( - Separator = '/' // OS-specific path separator - ListSeparator = 0 // OS-specific path list separator -) - -// isSeparator returns true if c is a directory separator character. -func isSeparator(c uint8) bool { - return Separator == c -} - // IsAbs returns true if the path is absolute. func IsAbs(path string) bool { return strings.HasPrefix(path, "/") || strings.HasPrefix(path, "#") diff --git a/src/pkg/path/filepath/path_unix.go b/src/pkg/path/filepath/path_unix.go index f8ac248fbb..ea555fc0e1 100644 --- a/src/pkg/path/filepath/path_unix.go +++ b/src/pkg/path/filepath/path_unix.go @@ -6,16 +6,6 @@ package filepath import "strings" -const ( - Separator = '/' // OS-specific path separator - ListSeparator = ':' // OS-specific path list separator -) - -// isSeparator returns true if c is a directory separator character. -func isSeparator(c uint8) bool { - return Separator == c -} - // IsAbs returns true if the path is absolute. func IsAbs(path string) bool { return strings.HasPrefix(path, "/") diff --git a/src/pkg/path/filepath/path_windows.go b/src/pkg/path/filepath/path_windows.go index dbd1c1e401..35302eb1ab 100644 --- a/src/pkg/path/filepath/path_windows.go +++ b/src/pkg/path/filepath/path_windows.go @@ -4,20 +4,11 @@ package filepath -const ( - Separator = '\\' // OS-specific path separator - ListSeparator = ':' // OS-specific path list separator -) - -// isSeparator returns true if c is a directory separator character. -func isSeparator(c uint8) bool { - // NOTE: Windows accept / as path separator. - return c == '\\' || c == '/' -} +import "os" // IsAbs returns true if the path is absolute. func IsAbs(path string) bool { - return path != "" && (volumeName(path) != "" || isSeparator(path[0])) + return path != "" && (volumeName(path) != "" || os.IsPathSeparator(path[0])) } // volumeName return leading volume name. @@ -28,7 +19,7 @@ func volumeName(path string) string { } // with drive letter c := path[0] - if len(path) > 2 && path[1] == ':' && isSeparator(path[2]) && + if len(path) > 2 && path[1] == ':' && os.IsPathSeparator(path[2]) && ('0' <= c && c <= '9' || 'a' <= c && c <= 'z' || 'A' <= c && c <= 'Z') { return path[0:2] |
