Signed-off-by: Stefan J. Wernli <swernli@microsoft.com>
| ... | ... |
@@ -15,7 +15,12 @@ const Prefix = `\\?\` |
| 15 | 15 |
// it does not already have it. |
| 16 | 16 |
func AddPrefix(path string) string {
|
| 17 | 17 |
if !strings.HasPrefix(path, Prefix) {
|
| 18 |
- path = Prefix + path |
|
| 18 |
+ if strings.HasPrefix(path, `\\`) {
|
|
| 19 |
+ // This is a UNC path, so we need to add 'UNC' to the path as well. |
|
| 20 |
+ path = Prefix + `UNC` + path[1:] |
|
| 21 |
+ } else {
|
|
| 22 |
+ path = Prefix + path |
|
| 23 |
+ } |
|
| 19 | 24 |
} |
| 20 | 25 |
return path |
| 21 | 26 |
} |
| 22 | 27 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,22 @@ |
| 0 |
+package longpath |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "strings" |
|
| 4 |
+ "testing" |
|
| 5 |
+) |
|
| 6 |
+ |
|
| 7 |
+func TestStandardLongPath(t *testing.T) {
|
|
| 8 |
+ c := `C:\simple\path` |
|
| 9 |
+ longC := AddPrefix(c) |
|
| 10 |
+ if !strings.EqualFold(longC, `\\?\C:\simple\path`) {
|
|
| 11 |
+ t.Errorf("Wrong long path returned. Original = %s ; Long = %s", c, longC)
|
|
| 12 |
+ } |
|
| 13 |
+} |
|
| 14 |
+ |
|
| 15 |
+func TestUNCLongPath(t *testing.T) {
|
|
| 16 |
+ c := `\\server\share\path` |
|
| 17 |
+ longC := AddPrefix(c) |
|
| 18 |
+ if !strings.EqualFold(longC, `\\?\UNC\server\share\path`) {
|
|
| 19 |
+ t.Errorf("Wrong UNC long path returned. Original = %s ; Long = %s", c, longC)
|
|
| 20 |
+ } |
|
| 21 |
+} |