diff options
| author | qmuntal <quimmuntal@gmail.com> | 2023-08-08 15:31:43 +0200 |
|---|---|---|
| committer | Quim Muntal <quimmuntal@gmail.com> | 2023-08-09 15:15:57 +0000 |
| commit | cd589c8a73415afbf94a8976f20cbed9d4061ba6 (patch) | |
| tree | 4570b35a090562f95db0b5fcfea51c9a00ea6b7b /src/os/path_windows_test.go | |
| parent | f617a6c8bf1ee3e54459f60acd2ec85ff31f6d4c (diff) | |
| download | go-cd589c8a73415afbf94a8976f20cbed9d4061ba6.tar.xz | |
os: make MkdirAll support volume names
MkdirAll fails to create directories under root paths using volume
names (e.g. //?/Volume{GUID}/foo). This is because fixRootDirectory
only handle extended length paths using drive letters (e.g. //?/C:/foo).
This CL fixes that issue by also detecting volume names without path
separator.
Updates #22230
Fixes #39785
Change-Id: I813fdc0b968ce71a4297f69245b935558e6cd789
Reviewed-on: https://go-review.googlesource.com/c/go/+/517015
Run-TryBot: Quim Muntal <quimmuntal@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Diffstat (limited to 'src/os/path_windows_test.go')
| -rw-r--r-- | src/os/path_windows_test.go | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/os/path_windows_test.go b/src/os/path_windows_test.go index 2506b4f0d8..4e5e501d1f 100644 --- a/src/os/path_windows_test.go +++ b/src/os/path_windows_test.go @@ -5,7 +5,11 @@ package os_test import ( + "fmt" + "internal/syscall/windows" + "internal/testenv" "os" + "path/filepath" "strings" "syscall" "testing" @@ -106,3 +110,48 @@ func TestOpenRootSlash(t *testing.T) { dir.Close() } } + +func testMkdirAllAtRoot(t *testing.T, root string) { + // Create a unique-enough directory name in root. + base := fmt.Sprintf("%s-%d", t.Name(), os.Getpid()) + path := filepath.Join(root, base) + if err := os.MkdirAll(path, 0777); err != nil { + t.Fatalf("MkdirAll(%q) failed: %v", path, err) + } + // Clean up + if err := os.RemoveAll(path); err != nil { + t.Fatal(err) + } +} + +func TestMkdirAllExtendedLengthAtRoot(t *testing.T) { + if testenv.Builder() == "" { + t.Skipf("skipping non-hermetic test outside of Go builders") + } + + const prefix = `\\?\` + vol := filepath.VolumeName(t.TempDir()) + `\` + if len(vol) < 4 || vol[:4] != prefix { + vol = prefix + vol + } + testMkdirAllAtRoot(t, vol) +} + +func TestMkdirAllVolumeNameAtRoot(t *testing.T) { + if testenv.Builder() == "" { + t.Skipf("skipping non-hermetic test outside of Go builders") + } + + vol, err := syscall.UTF16PtrFromString(filepath.VolumeName(t.TempDir()) + `\`) + if err != nil { + t.Fatal(err) + } + const maxVolNameLen = 50 + var buf [maxVolNameLen]uint16 + err = windows.GetVolumeNameForVolumeMountPoint(vol, &buf[0], maxVolNameLen) + if err != nil { + t.Fatal(err) + } + volName := syscall.UTF16ToString(buf[:]) + testMkdirAllAtRoot(t, volName) +} |
