-
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
Windows: Fix fs::canonicalize
to work with legacy drivers
#86447
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
@rustbot ping windows |
Hey Windows Group! This bug has been identified as a good "Windows candidate". cc @arlosi @danielframpton @gdr-at-ms @kennykerr @luqmana @lzybkr @nico-abram @retep998 @rylev @sivadeilra @wesleywiser |
For context, all paths are converted to a verbatim path by One potential issue I could think of is because of this it is somewhat common (although bad practice) to just strip the prefix |
In principle, I don't see any fundamental issues merging this PR, but it would be nice to see a new Note the crate dunce is frequently used as a wrapper over |
I've a concern here around user support. Yes, we do output weird paths on non-broken windows, but those paths generally don't look too wrong and people who triage issues are likely familiar with the rationale behind this. People complaining about the even weirder paths introduced by this PR will be rare enough to not allow for familiarity to become commonplace, but are also significantly more likely to file an issue upon encounter because these paths won't resemble anything people are used to. Either way I support the approach, I think. I definitely would appreciate Rust going above and beyond to handle a situation to at least try to handle my broken use-case. |
Yeah, that's my main concern. I think on balance it's worth it but I'm not totally confident in that.
I agree and it's on my todo list, unless somebody else gets there first. |
☔ The latest upstream changes (presumably #79965) made this pull request unmergeable. Please resolve the merge conflicts. |
efdf276
to
8cbea1f
Compare
☔ The latest upstream changes (presumably #87329) made this pull request unmergeable. Please resolve the merge conflicts. |
8cbea1f
to
d048712
Compare
Neither the PR or comments in the code point to the volume manager interface mentioned as required. Can you provide more information? |
fs::canonicalize
to work with broken driversfs::canonicalize
to work with legacy drivers
I've updated the OP and title to be more specific and less opinionated following our conversation. |
I think at the moment I'd like to pursue other options for addressing this issue. For example, in some situations So I'll close this for the time being. |
Attempts to fix: #59392, #79449, #59107, #54875, #52440, #52377, #48249, #74327, #55812
(sorry if I missed any)
The problem
On Windows, certain virtual drives (e.g. legacy RAM drives) manually create drive letter associations and mount points rather than going through the system Mount Manager (either directly or indirectly). The result of this means that volume management functions may fail. Unfortunately these functions include looking up the drive name, which in turn means that
std::fs::canonicalize
won't work.The workaround
The solution presented here is to detect when querying the drive name fails and fallback to using the NT kernel path. This can be used in win32 by prepending
\\?\GLOBALROOT
to the kernel path (as documented here). The downside of this solution is that it produces "weird" looking paths that a user may not recognise and other applications may not be able to use.E.g. this path:
May be canonicalized like so:
But it is at least usable by
std::fs
and it's perhaps better than having the crashes reported in some of the issues above.Conclusion
Working in the presence of these drivers can be tricky and normally I would just suggest this isn't Rust's problem (which it technically isn't). However, these drivers seem widespread enough that I think it makes sense to try to workaround them, at least in this specific case.