-
Notifications
You must be signed in to change notification settings - Fork 17.6k
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
os: File.ReadDir returns "The parameter is incorrect." when passed Windows device path (1.22 regression) #67834
Comments
cc @golang/windows |
I can't reproduce this issue. |
As noted, the code must be run under admin or you will get access denied trying to access the root device path. |
Ouch, thanks. I can reproduce it now. I'm not sure if this is a valid regression. Before go1.22, we were reading directories using the The side effect is that invalid device paths, like
Although it only mention GUID paths ( Note that running the CMD command |
I agree that that the previous behavior might have technically been "incorrect", but since it did work without any special handling by the program, it's also likely true that a lot of Go programs that previously handled root device paths fine in 1.21 will now fail in 1.22 (like the Kopia issue linked in the OP, or just any program that accepts user directory paths). The fact that these paths aren't properly handled by standard library functions like filepath.Clean() means that any file handling code that passed through these functions (which I would assume is quite a lot) will be broken with these kinds of device paths after 1.22, unless explicitly handled by each program. |
I agree that this issue should be fixed and backported. Unfortunately I don't have the bandwith to submit a fix now. Maybe @neild or @ianlancetaylor can help here. |
Sorry for the double post, but to clarify this a little more, filepath.Clean does actually have special handling for these paths, but only in specific circumstances. This mostly seems to be handled in go/src/internal/filepathlite/path_windows.go Lines 228 to 243 in 45967bb
then go/src/internal/filepathlite/path.go Lines 66 to 75 in 45967bb
So filepath.Clean does maintain the trailing slash for paths like Also note volumeNameLen references #64028 |
Please fill another issue for this bug. Thanks! |
Go version
1.22.4 windows/amd64
Output of
go env
in your module/workspace:What did you do?
Attempted to list a device path (
\\.\C:
) in Go 1.22 on Windows.Code, must be ran under admin:
Note this also happens for other device paths, not just
\\.\C:
. Other common device paths are things like\\?\Volume{...}
,\\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy...
, etc. This issue was encountered at kopia/kopia#3842 when dealing with Windows Shadow Copy Volumes in 1.22.What did you see happen?
What did you expect to see?
This code works as expected in 1.21.10, thus it seems to be a regression.
In 1.22, you can restore the previous behavior by appending a backslash
\
to the path:but these kinds of paths with trailing backslashes are mangled by functions like
filepath.Clean
and have the backslash stripped.filepath.Clean
has exceptions for root windows paths likeC:\
, but these exceptions aren't applied to device paths.The text was updated successfully, but these errors were encountered: