From 6d223febda5fd3f27824d9dda7de1b18e50d0be5 Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Fri, 25 Sep 2015 14:00:56 -0700 Subject: [PATCH] Windows: Fixing longpath hanlding of UNC paths. Signed-off-by: Stefan J. Wernli --- pkg/longpath/longpath.go | 7 ++++++- pkg/longpath/longpath_test.go | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 pkg/longpath/longpath_test.go diff --git a/pkg/longpath/longpath.go b/pkg/longpath/longpath.go index 1dcc10a2d4..9b15bfff4c 100644 --- a/pkg/longpath/longpath.go +++ b/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 } diff --git a/pkg/longpath/longpath_test.go b/pkg/longpath/longpath_test.go new file mode 100644 index 0000000000..01865eff09 --- /dev/null +++ b/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) + } +}