Skip to content

Conversation

cning112
Copy link
Contributor

@cning112 cning112 commented Aug 28, 2024

Summary

This PR addresses an issue on Windows where std::fs::canonicalize can fail or panic when resolving paths on mapped network drives. By replacing it with Simplified::simple_canonicalize, we aim to improve the robustness and cross-platform compatibility of path resolution.

Changes

  • Updated CANONICAL_CWD in path.rs to use Simplified::simple_canonicalize instead of std::fs::canonicalize.

Why

  • std::fs::canonicalize has known issues with resolving paths on mapped network drives on Windows, which can lead to panics or incorrect path resolution.
  • Simplified::simple_canonicalize internally uses dunce::canonicalize, which handles these cases more gracefully, ensuring better stability and reliability.

Test Plan

Since simple_canonicalize has already been tested in a prior PR, this change is expected to work without introducing any new issues. No additional tests are necessary beyond ensuring existing tests pass, which will confirm the correctness of the change.

…e for CANONICAL_CWD to improve reliability on Windows, particularly when resolving paths on mapped network drives.
@cning112 cning112 changed the title fix: replace std::fs::canonicalize with Simplifed::simple_canonicaliz… fix: replace std::fs::canonicalize with Simplified::simple_canonicaliz… Aug 29, 2024
@charliermarsh charliermarsh added the windows Specific to the Windows platform label Aug 29, 2024
@charliermarsh
Copy link
Member

Interesting. But doesn't dunce::canonicalize just call fs::canonicalize under the hood? My read of the code is it's just fs::canonicalize with a post-processing step to remove the prefixes.

… canonicalized on Windows (e.g. on a network drive or RAM drive), fallback to `std::path::absolute()` if the path exists
@cning112
Copy link
Contributor Author

Absolutely true. Paths that can't be canonicalized by fs:: canonicalize are also beyond the capability of dunce:: canonicalize.

In the latest commit, I updated the Simplified::simple_canonicalize for paths that can't be canonicalised on Windows: it falls back on std::path::absolute and verifies if the path exists.

I've tested it locally on a mapped network drive on Windows, where the latest version of uv pip compile panicked as the path can't be canonicalized. But I am not sure how to add a unit test for this 😬

@charliermarsh
Copy link
Member

Ok, I think something like this is reasonable, but I may follow-up to reduce the scope a bit.

@charliermarsh charliermarsh merged commit ae3f35c into astral-sh:main Sep 1, 2024
57 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

windows Specific to the Windows platform

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants