Просмотр исходного кода

Merge pull request #16594 from Microsoft/sjw/unc-build-fix

Windows: Fixing longpath hanlding of UNC paths.
Jess Frazelle 9 лет назад
Родитель
Сommit
d04fd5e0dc
2 измененных файлов с 28 добавлено и 1 удалено
  1. 6 1
      pkg/longpath/longpath.go
  2. 22 0
      pkg/longpath/longpath_test.go

+ 6 - 1
pkg/longpath/longpath.go

@@ -15,7 +15,12 @@ const Prefix = `\\?\`
 // it does not already have it.
 func AddPrefix(path string) string {
 	if !strings.HasPrefix(path, Prefix) {
-		path = Prefix + path
+		if strings.HasPrefix(path, `\\`) {
+			// This is a UNC path, so we need to add 'UNC' to the path as well.
+			path = Prefix + `UNC` + path[1:]
+		} else {
+			path = Prefix + path
+		}
 	}
 	return path
 }

+ 22 - 0
pkg/longpath/longpath_test.go

@@ -0,0 +1,22 @@
+package longpath
+
+import (
+	"strings"
+	"testing"
+)
+
+func TestStandardLongPath(t *testing.T) {
+	c := `C:\simple\path`
+	longC := AddPrefix(c)
+	if !strings.EqualFold(longC, `\\?\C:\simple\path`) {
+		t.Errorf("Wrong long path returned. Original = %s ; Long = %s", c, longC)
+	}
+}
+
+func TestUNCLongPath(t *testing.T) {
+	c := `\\server\share\path`
+	longC := AddPrefix(c)
+	if !strings.EqualFold(longC, `\\?\UNC\server\share\path`) {
+		t.Errorf("Wrong UNC long path returned. Original = %s ; Long = %s", c, longC)
+	}
+}