Skip to content

Use absolute_path instead of fs::canonicalize #4131

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

Merged
merged 3 commits into from
Apr 21, 2020

Conversation

topecongiro
Copy link
Contributor

This PR is a successor of #3590.

Copy link
Member

@calebcartwright calebcartwright left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@topecongiro
Copy link
Contributor Author

I am still not sure this will work in all cases, but I will merge this for now.

@topecongiro topecongiro merged commit 5e667d3 into rust-lang:master Apr 21, 2020
@topecongiro topecongiro deleted the windows-absolute_path branch April 21, 2020 02:47
@rivy
Copy link

rivy commented Apr 21, 2020

@topecongiro , this will likely fail for deep paths even on later version Windows 10 installations. The removal of the MAX_PATH (~260 characters) limitation is opt-in and has to have a registry value set (see https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#enable-long-paths-in-windows-10-version-1607-and-later). That's an impossible bar to expect from any significant user population. It can't really be counted on at all.

However, there is an available solution... extended-paths. Extended-paths (marked by a leading \\?\ prefix) can be used with versions of the windows API back to at least Windows 7. If the path length is greater than (or even close to) MAX_PATH, it should be converted to an extended-path by converting it to an absolute path, converting all forward slashes to backslashes, and prefixing it with \\?\.

I referenced the needed solution for this in the original issue/PR.

This type of path construction can even be used to access windows wierdo reserved paths like NUL and CON.

Please see the dunce crate which does a very good job in navigating these weird MS path waters.

@topecongiro
Copy link
Contributor Author

@rivy Hmm, I will take a look again, but the dance crate looks promising. We might as well use it. Thank you for your information

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants