Skip to content

path/filepath: use Windows GetFinalPathNameByHandle instead of os.Readlink to implement EvalSymlinks #20506

@darstahl

Description

@darstahl

What version of Go are you using (go version)?

go version go1.8.1 windows/amd64

What operating system and processor architecture are you using (go env)?

set GOARCH=amd64
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows

What did you do?

When a directory junction points to a path in the NT Namespace (See this MSDN page for details) that starts with \\?\ os.Readlink strips the leading \\?\ which results in returning an invalid path.

This requires cmd to create the Junction, so doesn't seem to work on play.golang.org. I've uploaded a repro to https://github.com/darrenstahlmsft/ReadJunction

To run the repro, run mountvol.exe which will print out:

Possible values for VolumeName along with current mount points are:

    \\?\Volume{7d396648-0527-4fed-9cae-5d961ec7311a}\
        C:\

Replace the folderPath in main.go with the retrieved volume GUID path then run main.go.

What did you expect to see?

When run in go1.7.5 this works as expected and returns:

$ go run main.go
Junction created for test_junction <<===>> \\?\Volume{7d396648-0527-4fed-9cae-5d961ec7311a}\

Readlink returned: \\?\Volume{7d396648-0527-4fed-9cae-5d961ec7311a}\

What did you see instead?

When run in go1.8.1 the returned path is invalid:

$ go run main.go
Junction created for test_junction <<===>> \\?\Volume{7d396648-0527-4fed-9cae-5d961ec7311a}\

Readlink returned: Volume{7d396648-0527-4fed-9cae-5d961ec7311a}\

/cc @jstarks

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions