summaryrefslogtreecommitdiff
path: root/src/pkg/path/filepath/path_windows.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/path/filepath/path_windows.go')
-rw-r--r--src/pkg/path/filepath/path_windows.go35
1 files changed, 33 insertions, 2 deletions
diff --git a/src/pkg/path/filepath/path_windows.go b/src/pkg/path/filepath/path_windows.go
index 2535697fd..9692fd978 100644
--- a/src/pkg/path/filepath/path_windows.go
+++ b/src/pkg/path/filepath/path_windows.go
@@ -4,7 +4,13 @@
package filepath
-import "strings"
+import (
+ "strings"
+)
+
+func isSlash(c uint8) bool {
+ return c == '\\' || c == '/'
+}
// IsAbs returns true if the path is absolute.
func IsAbs(path string) (b bool) {
@@ -16,11 +22,12 @@ func IsAbs(path string) (b bool) {
if path == "" {
return false
}
- return path[0] == '/' || path[0] == '\\'
+ return isSlash(path[0])
}
// VolumeName returns leading volume name.
// Given "C:\foo\bar" it returns "C:" under windows.
+// Given "\\host\share\foo" it returns "\\host\share".
// On other platforms it returns "".
func VolumeName(path string) (v string) {
if len(path) < 2 {
@@ -33,6 +40,30 @@ func VolumeName(path string) (v string) {
'A' <= c && c <= 'Z') {
return path[:2]
}
+ // is it UNC
+ if l := len(path); l >= 5 && isSlash(path[0]) && isSlash(path[1]) &&
+ !isSlash(path[2]) && path[2] != '.' {
+ // first, leading `\\` and next shouldn't be `\`. its server name.
+ for n := 3; n < l-1; n++ {
+ // second, next '\' shouldn't be repeated.
+ if isSlash(path[n]) {
+ n++
+ // third, following something characters. its share name.
+ if !isSlash(path[n]) {
+ if path[n] == '.' {
+ break
+ }
+ for ; n < l; n++ {
+ if isSlash(path[n]) {
+ break
+ }
+ }
+ return path[:n]
+ }
+ break
+ }
+ }
+ }
return ""
}