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: Rel() fails on Windows when only one parameter has \\?\ prefix #68847

Open
dmcardle opened this issue Aug 12, 2024 · 4 comments
Open
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Milestone

Comments

@dmcardle
Copy link

Go version

go version devel go1.24-47cdc43289 Mon Aug 12 13:09:41 2024 -0400 windows/amd64

Output of go env in your module/workspace:

PS C:\Users\Dan\REPOS\go\src> ..\bin\go.exe env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Dan\AppData\Local\go-build
set GOENV=C:\Users\Dan\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\Dan\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\Dan\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Users\Dan\REPOS\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Users\Dan\REPOS\go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=devel go1.24-47cdc43289 Mon Aug 12 13:09:41 2024 -0400
set GODEBUG=
set GOTELEMETRY=local
set GOTELEMETRYDIR=C:\Users\Dan\AppData\Roaming\go\telemetry
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=0
set GOMOD=C:\Users\Dan\REPOS\go\src\go.mod
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\Dan\AppData\Local\Temp\go-build933240645=/tmp/go-build -gno-record-gcc-switches

What did you do?

What did you see happen?

--- FAIL: TestRelWindows (0.00s)
    path_windows_test.go:734: Rel("C:\\foo", "\\\\?\\C:\\foo\\bar") = "", Rel: can't make \\?\C:\foo\bar relative to C:\foo; want "bar"
    path_windows_test.go:734: Rel("C:/foo", "//?/C:/foo/bar") = "", Rel: can't make //?/C:/foo/bar relative to C:/foo; want "bar"
    path_windows_test.go:734: Rel("\\\\?\\C:\\foo", "C:\\foo\\bar") = "", Rel: can't make C:\foo\bar relative to \\?\C:\foo; want "bar"
    path_windows_test.go:734: Rel("//?/C:/foo", "C:/foo/bar") = "", Rel: can't make C:/foo/bar relative to //?/C:/foo; want "bar"
FAIL
FAIL    path/filepath   1.568s

What did you expect to see?

The demo CL (https://go-review.googlesource.com/c/go/+/604875/3) contains several expectations, but I'll pick one. I'm particularly surprised that the relative path from basepath \\?\C:\foo to targpath \\?\C:\foo\bar is an error instead of bar.

I'm a little out of my depth, but this Microsoft documentation (https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#win32-file-namespaces) seems to indicate that \\?\ is just a way of turning off string parsing in Windows APIs.

I think it should be possible to work around this limitation, for instance by prefixing \\?\ onto the parameters when they are already absolute paths.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/604875 mentions this issue: path/filepath: Add test to demonstrate Rel() quirk on Windows

@ianlancetaylor
Copy link
Contributor

CC @neild @golang/windows

@ianlancetaylor ianlancetaylor added OS-Windows NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Aug 12, 2024
@ianlancetaylor ianlancetaylor added this to the Backlog milestone Aug 12, 2024
@alexbrainman
Copy link
Member

I agree with @dmcardle that \\?\ prefix should be ignored when comparing files in filepath.Rel.

All tests in https://go-review.googlesource.com/c/go/+/604875 should pass.

Alex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Projects
None yet
Development

No branches or pull requests

5 participants