-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Automatically insert \\?\
where needed on Windows
#32689
Comments
There has already been a desire for something like this, and even an attempt at implementing this. However, doing something like this is somewhat complicated due to all the weird edge cases in how paths are handled on Windows. The current recommended solution is to create an external crate that handles normalizing paths and once all the kinks have been worked out of it and all the edge cases tested, then we will be able to consider whether to add something like that to libstd. |
The documentation says that for long filenames, you need to prepend |
@dgrunwald Which is exactly why it is so complicated because that means we have to handle all the weird edge cases ourselves! Hence the desire to have it worked out in an external crate first. |
It would be great if we could properly implement such a feature in Rust stdlib, but the benefit might be marginal because many Windows tools either don't understand
|
@nodakai That is still not a good enough reason to implement the best support possible. Don't take my word for it – the CoreCLR team had the same decision! See this CoreFX issue which was fixed using essentially the same technique I am proposing, and was the inspiration for my suggestion. |
@dgrunwald This is false. GetFullPathNameW does not care about It is the fact that a Windows API call can be used to do all of the hard work for us that makes this practical. Otherwise, it would be too error-prone. |
I did a quick test and |
Should I try to implement this? On Aug 8, 2016 10:40 PM, "Peter Atashian" notifications@github.com wrote:
|
@DemiMarie I don't see why not. Feel free to give it a shot. |
I just realized a problem: This means that Rust must either
Indeed, the MSDN documentation states that multithreaded programs and all shared libraries should not use relative path names at all. Presumably, such code should fail if given a relative path name. MSDN says that relative paths provided by the user should be converted to absolute paths while the program is still single-threaded. On the other hand, CoreFX does call this function, so I guess it is okay. |
@DemiMarie What do you mean by undefined behavior? The way it is implemented, the current directory is stored in the PEB, and all access to the PEB goes through the |
Sorry, I did not know that. The MSDN docs seemed to say otherwise. On Aug 13, 2016 7:45 PM, "Peter Atashian" notifications@github.com wrote:
|
On Windows platform, AlphaFS can help you out. |
Triage: no changes that I'm aware of |
libstd
should automatically insert\\?\
when necessary. The path must be canonicalized first; this can be done using the Windows API functionGetFullPathNameW
.A necessary condition for needing to call
GetFullPathNameW
is that the path does not begin with\\?\
. Afterwards, if the path begins with\\
but not\\?\
, the\\
must be replaced with\\?\UNC\
.The text was updated successfully, but these errors were encountered: