返回 DeepSeek-Reasonix
longpath_windows_test.go
根目录 / internal / persistentshell / longpath_windows_test.go
1 package persistentshell
2
3 import (
4 "path/filepath"
5
6 "golang.org/x/sys/windows"
7 )
8
9 // longPath expands 8.3 short-name aliases (e.g. HELLOF~1 when TEMP is a short
10 // path): PowerShell's Set-Location cannot enter a directory spelled with one.
11 // The original spelling is kept on failure, so the harness still gets a real
12 // directory on volumes without long-name expansion.
13 func longPath(path string) string {
14 cleaned := filepath.Clean(path)
15 input, err := windows.UTF16PtrFromString(cleaned)
16 if err != nil {
17 return cleaned
18 }
19 buffer := make([]uint16, 32768)
20 n, err := windows.GetLongPathName(input, &buffer[0], uint32(len(buffer)))
21 if err != nil || n == 0 || n >= uint32(len(buffer)) {
22 return cleaned
23 }
24 return windows.UTF16ToString(buffer[:n])
25 }
26
26 lines GO