mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Windows: Fixing longpath hanlding of UNC paths.
Signed-off-by: Stefan J. Wernli <swernli@microsoft.com>
This commit is contained in:
parent
724b410c55
commit
6d223febda
2 changed files with 28 additions and 1 deletions
|
@ -15,7 +15,12 @@ const Prefix = `\\?\`
|
||||||
// it does not already have it.
|
// it does not already have it.
|
||||||
func AddPrefix(path string) string {
|
func AddPrefix(path string) string {
|
||||||
if !strings.HasPrefix(path, Prefix) {
|
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
|
return path
|
||||||
}
|
}
|
||||||
|
|
22
pkg/longpath/longpath_test.go
Normal file
22
pkg/longpath/longpath_test.go
Normal file
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue