-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Use verbatim paths by default #27916
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
Example of a program that doesn't work before, but works afterwards:
|
This enables users of the Rust standard library to ignore the limit of 260 "characters" per file name – instead the new limit is around 32K "characters". See also "Naming Files, Paths, and Namespaces" on MSDN, section "Maximum Path Name Limitations": https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx In order to use verbatim paths, the following conversions are performed: - `C:\` -> `\\?\C:\`. - `\\server\share\` -> `\\?\UNC\server\share\`. - `..` are evaluated by popping the last component. - `.` are dropped. - Relative paths are joined with `os::current_dir` (Special case: Path name is along the lines of `C:foobar`. This is a relative path if the current directory is on drive `C:`, otherwise it's an absolute path).
Out of curiosity, is there precedent for this in other I/O libraries? In general I think it's quite valuable that we perform 0 interpretation of the path coming into these APIs and allow the underlying system APIs to interpret them however they'd like. In the past any sort of layering we add on top inevitably breaks some obscure case in some API, so just passing everything through seems like the best option. |
I don't know – haven't looked it up, although I couldn't find something with a quick google search.
It's pretty hard to say something to that, as this is pretty hand-wavy – the pull request is not adding it to all functions, but rather it can be reviewed on a case-by-case basis for each function by looking at its documentation (EDIT: I guess one should look a bit at the link functions for this). I think we already do some kind of normalization already, namely stripping empty path components (?). EDIT2: It'd also be valuable that you wouldn't have to care about Windows' quirks about path lengths in Rust programs. |
Documentation of the functions, in order of appearance in the source code: All these functions (except for the link functions) are documented with:
This means the official documentation recommends using these "\?" in order to get around the The |
After doing some testing locally, it appears that |
@retep998 Yea, I also read that Windows just normalizes the paths before passing them to the file system. I guess we can create public APIs once this has landed. |
I agree that it's kinda annoying to deal with path length restrictions on Windows, but I'm pretty uneasy about forging ahead here without any prior art. These sorts of conversions have historically been always wrong in one way or another for us, hence our strategy in I think it may be best to develop this sort of functionality externally on crates.io first and see how it plays out before moving it into the standard library to happen by default. |
Closing for now I guess (as a reminder, if this is to be adopted, fix the CreateSymbolicLink function). |
This enables users of the Rust standard library to ignore the limit of 260
"characters" per file name – instead the new limit is around 32K "characters".
See also "Naming Files, Paths, and Namespaces" on MSDN, section "Maximum Path
Name Limitations":
https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx
In order to use verbatim paths, the following conversions are performed:
C:\
->\\?\C:\
.\\server\share\
->\\?\UNC\server\share\
...
are evaluated by popping the last component..
are dropped.os::current_dir
(Special case: Path name isalong the lines of
C:foobar
. This is a relative path if the currentdirectory is on drive
C:
, otherwise it's an absolute path).