-
-
Notifications
You must be signed in to change notification settings - Fork 6
A crate to handle Windows' "exotic" paths #34
Comments
Is this something that could be fixed in fs::canonicalize and Path::join? If not, is that because of backward compatibility restrictions or because the current behavior is useful and worth keeping? If the latter, how would the spec for this new library's canonicalize and join functionality be different from what std canonicalize and join claim to do? |
So @retep998 knows this better than I. My impression is that the My impression is that the |
Thanks, makes sense. Would something like the following API be sufficient for what Cargo needs? : pub struct SanePath {...}
impl SanePath {
pub fn normalize<P: AsRef<Path>>(path: P) -> Self;
pub fn join<P: AsRef<Path>>(&self, path: P) -> Self;
pub fn as_std_path(&self) -> &Path;
}
impl AsRef<Path> for SanePath {...} |
Yes! Or freestanding functions: pub fn normalize<P: AsRef<Path>>(path: P) -> PathBuf {...}
pub fn join<P: AsRef<Path>>(base: &mut PathBuf, addition: P) {...} |
|
I'd like to tackle this one, but from this issue I didn't understand whether popping on a |
I think it is ok to brake symlinks. |
Are https://crates.io/crates/path-absolutize and https://crates.io/crates/path-dedot what you need? |
Thanks for the links. Now that I have had time to read it carefully... I don't know. |
I saw a post related to this on Reddit recently, and I'd like to try implementing this. @Eh2406 @dtolnay could you have a look at my repository (https://github.com/ajeetdsouza/pathology) and tell me your initial thoughts? I've currently only written an implementation for Windows, but I'm working on one for Linux too. The only function I've implemented is On Windows, I'm using On Linux, there is no system call to lexically normalize paths, but GNU |
Update: I've added |
@ajeetdsouza sorry for the slow reply. That looks like a great start on a answer to the question "I use @retep998 may be able to revue the windows api calls better than I. |
Related note for others, dunce is an alternative to |
normpath can now be used to solve this issue. It defines It would be great if @retep998 could review this crate as well. |
@Eh2406 What would be the next steps for integrating this into Cargo? |
Last time I had this paged in rust-lang/cargo#6198 was the best link. Looks like we just got a related PR rust-lang/cargo#8874, so coordinating my make sense. Another good place to start would be to grep for |
@Eh2406 Thanks. I'll start looking through where the path handling can be improved |
Std path does some weird things with UNC paths (
\\?\
). For one std::fs::canonicalize always returns one whether it is needed or not. Thenpath.join
will just do a string concatenation leading to invalid paths. This leads to bugs in many important parts of the ecosystem. (Cargo, wasm-pack, Rustup)So we need a library that provides a binding to
GetFullPathNameW
on windows and usesstd::fs::canonicalize
otherwize.More ambitiously we need a path "interpreter" that "
..
and.
while appending. So if you started with\\?\C:\bar
and joined../foo
you would iterate the components of../foo
and apply them to the base path, first applying..
to get\\?\C:\
and then applyingfoo
to get\\?\C:\foo
."Ether part of this would be a valuable addition to the ecosystem!
The text was updated successfully, but these errors were encountered: