mirror of
https://github.com/golang/go
synced 2024-11-12 02:00:23 -07:00
os: handle backslash and slash both in the path on Windows
Fixes #35492 Change-Id: I00dce8fd1228f809e0c61013ac4de7a5953cbbf9 Reviewed-on: https://go-review.googlesource.com/c/go/+/206997 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
608b94bef2
commit
e77106cc54
@ -111,10 +111,17 @@ func openDir(name string) (file *File, err error) {
|
||||
|
||||
path := fixLongPath(name)
|
||||
|
||||
if len(path) == 2 && path[1] == ':' || (len(path) > 0 && path[len(path)-1] == '\\') { // it is a drive letter, like C:
|
||||
if len(path) == 2 && path[1] == ':' { // it is a drive letter, like C:
|
||||
mask = path + `*`
|
||||
} else if len(path) > 0 {
|
||||
lc := path[len(path)-1]
|
||||
if lc == '/' || lc == '\\' {
|
||||
mask = path + `*`
|
||||
} else {
|
||||
mask = path + `\*`
|
||||
}
|
||||
} else {
|
||||
mask = path + `\*`
|
||||
mask = `\*`
|
||||
}
|
||||
maskp, e := syscall.UTF16PtrFromString(mask)
|
||||
if e != nil {
|
||||
|
@ -74,3 +74,18 @@ func TestMkdirAllExtendedLength(t *testing.T) {
|
||||
t.Fatalf("MkdirAll(%q) should have failed, but did not", path)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOpenRootSlash(t *testing.T) {
|
||||
tests := []string{
|
||||
`/`,
|
||||
`\`,
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
dir, err := os.Open(test)
|
||||
if err != nil {
|
||||
t.Fatalf("Open(%q) failed: %v", test, err)
|
||||
}
|
||||
dir.Close()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user