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

Support Windows local device paths in Path #15590

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

HertzDevil
Copy link
Contributor

There are 7 types of user-space paths on Win32:

  • Drive-absolute (C:\foo)
  • Drive-relative (C:foo)
  • Rooted (\foo)
  • Relative (foo)
  • UNC absolute (\\server\share\foo)
  • Local device (\\.\NUL, \\?\C:\foo)
  • Root local device (\\., \\?)

Local device paths starting with exactly \\?\ are also known as raw local device paths. Other than this prefix, all forward and backward slashes are interchangeable.

Path already recognizes the first 5 of them; this PR adds the remaining 2. As noted in #15587, the \\.\ prefix appears when dealing with special devices, such as \\.\NUL and \\.\COM15, as well as named pipes. The \\?\ prefix is useful when passing paths to Win32 functions that are already normalized, or if the path exceeds 260 UTF-16 code units (see also #13420).

This does not cover NT paths of the form \??\.... They appear in the reparse data area of Windows symbolic links.

Depends on #15583 and #15584.

@HertzDevil HertzDevil marked this pull request as ready for review March 24, 2025 09:44
@straight-shoota
Copy link
Member

I'm not quite sure that I understand if there's a difference between \\?\ and //?/ prefix (or the same pattern with a mixture of different separators).
Would it make sense to add some more specs for that? parent, parents and dirname to not have examples with \\? prefix, for example.

@HertzDevil
Copy link
Contributor Author

HertzDevil commented Mar 24, 2025

Only exactly \\?\ represents a raw local device path, all other combinations of slashes and . / ? are equivalent when it comes to filesystem access.

As Path doesn't access the filesystem, the exact prefix truly shouldn't make a difference here for Windows paths.

@straight-shoota
Copy link
Member

What about adding some specs with \\?\ prefix for normalize, parent, parents and dirname?
Ideally every example with //?/ should be accompanied by one with \\?\.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:feature platform:windows Windows support based on the MSVC toolchain / Win32 API topic:stdlib:files
Projects
Status: Review
Development

Successfully merging this pull request may close these issues.

2 participants