-
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
Add try_canonicalize
to rustc_fs_util
and use it over fs::canonicalize
#109231
Conversation
(rustbot has picked a reviewer for you, use r? to override) |
These commits modify the If this was intentional then you can ignore this comment. These commits modify compiler targets. |
r? compiler |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some Windows background info:
- The
canonicalize
function will fail on filesystem drivers that don't fully implement the kernel interface (most notably ImDisk RAM drives). - Paths starting with
\\?\
(whichcanonicalize
returns) are sometimes necessary to avoid path length limitations. However, std will now take care of this automatically. std::path::absolute
gets an absolute path without touching the filesystem, thus it should never fail on a valid path. However, it does not resolve symlinks.
So trying fs::canonicalize
and falling back to path::absolute
will suite most cases. The only issue I see would be if it's vital for symlinks to be resolved. (I did have a patch that would make canonicalize
work even in the presence of ImDisk but people were understandably nervous of the weird paths it produces in that case).
Is this something that's fixable? Or would the fix just be to move |
@bors r+ |
It's fixable if either a) we fix all the faulty drivers in the world or b) are ok with returning some weird paths. The first would be fairly difficult to do and the second is seen as being far from ideal.
We could have a function that attempts to clean up the |
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#106964 (Clarify `Error::last_os_error` can be weird) - rust-lang#107718 (Add `-Z time-passes-format` to allow specifying a JSON output for `-Z time-passes`) - rust-lang#107880 (Lint ambiguous glob re-exports) - rust-lang#108549 (Remove issue number for `link_cfg`) - rust-lang#108588 (Fix the ffi_unwind_calls lint documentation) - rust-lang#109231 (Add `try_canonicalize` to `rustc_fs_util` and use it over `fs::canonicalize`) - rust-lang#109472 (Add parentheses properly for method calls) - rust-lang#109487 (Move useless_anynous_reexport lint into unused_imports) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
I'm starting to think that |
That would be a breaking change so isn't on the table. More over there are cases (e.g. in security contexts) where you do actually want to resolve symlinks. So it is a useful function. A new function would be a better way forward. |
I guess we kind of need a function which returns absolute paths which can resolve |
If an SMB server can't resolve a component it will return an error (although of course this is ultimately up to the remote server, which can just straight up lie if it wants to).
|
Add `try_canonicalize` and use it over `std::fs::canonicalize` This adds a `try_canonicalize` function that calls `std::fs::canonicalize` and on Windows falls back to getting an absolute path. Uses of `canonicalize` have been replaced with `std::fs::canonicalize`. On Windows `std::fs::canonicalize` may fail due to incomplete drivers. In particular `ImDisk` does not support it. Combined with rust-lang/rust#109231 this allows compiling crates on an `ImDisk` RAM disk and I've tested that it works with various configuration using [rcb](https://github.com/Zoxc/rcb).
This adds
try_canonicalize
which tries to callfs::canonicalize
, but falls back tostd::path::absolute
if it fails. Existingcanonicalize
calls are replaced with it.fs::canonicalize
is not guaranteed to work on Windows.