Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

path/filepath: revert "path/filepath: fix EvalSymLink documentation" #40178

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/os/file_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ func openSymlink(path string) (syscall.Handle, error) {
// \??\C:\foo\bar into C:\foo\bar
// \??\UNC\foo\bar into \\foo\bar
// \??\Volume{abc}\ into C:\
// \??\Volume{abc}\ into \\?\Volume{abc} if GetFinalPathNameByHandle(,,,VOLUME_NAME_DOS) returns PATH_NOT_FOUND (3)
func normaliseLinkPath(path string) (string, error) {
if len(path) < 4 || path[:4] != `\??\` {
// unexpected path, return it as is
Expand Down Expand Up @@ -431,8 +432,15 @@ func normaliseLinkPath(path string) (string, error) {
defer syscall.CloseHandle(h)

buf := make([]uint16, 100)
isVolumeNameGUID := false
for {
n, err := windows.GetFinalPathNameByHandle(h, &buf[0], uint32(len(buf)), windows.VOLUME_NAME_DOS)
if errors.Is(err, ErrNotExist) {
n, err = windows.GetFinalPathNameByHandle(h, &buf[0], uint32(len(buf)), windows.VOLUME_NAME_GUID)
if err == nil {
isVolumeNameGUID = true
}
}
if err != nil {
return "", err
}
Expand All @@ -443,7 +451,9 @@ func normaliseLinkPath(path string) (string, error) {
}
s = syscall.UTF16ToString(buf)
if len(s) > 4 && s[:4] == `\\?\` {
s = s[4:]
if !isVolumeNameGUID {
s = s[4:]
}
if len(s) > 3 && s[:3] == `UNC` {
// return path like \\server\share\...
return `\` + s[3:], nil
Expand Down