Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upAdding Path.normalize() method #47363
Conversation
ThatsGobbles
added some commits
Nov 11, 2017
rust-highfive
assigned
joshtriplett
Jan 11, 2018
This comment has been minimized.
This comment has been minimized.
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @joshtriplett (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
This comment has been minimized.
This comment has been minimized.
|
I don't see any tests for |
This comment has been minimized.
This comment has been minimized.
|
@retep998: Those are good points, I can add those tests. What would be some other good Windows-specific tests to include? I must note, I don't have access to a Windows dev box, so it's tricky to run these Windows-specific tests. |
This comment has been minimized.
This comment has been minimized.
|
At the very least, we should have every single example from the tables on https://googleprojectzero.blogspot.com/2016/02/the-definitive-guide-on-win32-to-nt.html |
This comment has been minimized.
This comment has been minimized.
|
You should also include test cases for filenames containing spaces, tabs, newlines, and all three. Please use raw strings for filenames containing backslashes, so that the test cases don't need to escape backslashes. |
This comment has been minimized.
This comment has been minimized.
|
@rust-lang/libs Do we want to use |
This comment has been minimized.
This comment has been minimized.
|
@retep998 If we don't use |
kennytm
added
T-libs
S-waiting-on-review
labels
Jan 11, 2018
This comment has been minimized.
This comment has been minimized.
|
Does |
This comment has been minimized.
This comment has been minimized.
|
@ThatsGobbles According to the MSDN documentation, "This function does not verify that the resulting path and file name are valid, or that they see an existing file on the associated volume." It does, however, look at the process's current working directory. |
This comment has been minimized.
This comment has been minimized.
|
I managed to get a Windows 10 VM up and running, and am trying out tests. The normalization does not seem to like the examples in The Definitive Guide to NT and Win32 Paths involving trailing dots and spaces at the end of a path (the |
This comment has been minimized.
This comment has been minimized.
|
It appears that this Windows shell function does what I'm aiming to do with my function! Now the question would be, how do I get access to it in my Rust code? |
ThatsGobbles
added some commits
Jan 12, 2018
This comment has been minimized.
This comment has been minimized.
|
As it turns out, I'm not really sure what I should be doing to get this working. I don't know anything about Windows C FFI in Rust, which is stopping me from using the PathCch methods (not to mention, I'd like for normalize to be a pure function that can't fail, and relying on a Windows API seems like it introduces the possibility of failure). Are there any guides or reading I can look at to get my feet wet with this? |
This comment has been minimized.
This comment has been minimized.
|
I'm going to defer to @retep998 here. |
This comment has been minimized.
This comment has been minimized.
|
Ping @retep998! Do you have any advice for @ThatsGobbles ? |
carols10cents
added
S-waiting-on-author
and removed
S-waiting-on-review
labels
Jan 22, 2018
This comment has been minimized.
This comment has been minimized.
|
Hello all, I concur with the name change: As for tests, I've been incorporating the examples from the linked page, but I'm running into issues with Windows paths. It seems that |
ThatsGobbles
added some commits
Feb 6, 2018
kennytm
requested changes
Feb 6, 2018
| /// ``` | ||
| #[unstable(feature = "path normalize", issue = "47402")] | ||
| pub fn normalize(&self) -> PathBuf { | ||
| #[unstable(feature = "path cleaning", issue = "47402")] |
This comment has been minimized.
This comment has been minimized.
kennytm
approved these changes
Feb 6, 2018
ThatsGobbles
added some commits
Feb 6, 2018
kennytm
reviewed
Feb 6, 2018
| tc!("/../../", "/"); | ||
| } else { | ||
| // Drive-absolute paths. | ||
| tc!(r#"X:\ABC\DEF"#, r#"X:\ABC\DEF"#); |
This comment has been minimized.
This comment has been minimized.
kennytm
Feb 6, 2018
Member
Nit pick. Unless your path contains a " you could just lose the #s
tc!(r"X:\ABC\DEF", r"X:\ABC\DEF");I think this is much less noisy.
This comment has been minimized.
This comment has been minimized.
BatmanAoD
commented
Feb 13, 2018
|
Ping from triage! @kennytm and @joshtriplett , it looks like the author needs some help dealing with Windows paths. Can either of you recommend someone who might be able to help? Or should we tag a team? I've also asked on IRC. |
This comment has been minimized.
This comment has been minimized.
|
@ThatsGobbles Could you list the test cases which tripped up |
This comment has been minimized.
This comment has been minimized.
|
@ThatsGobbles Ping from the release team :) Did you have a chance to take a look into what @kennytm proposed to do? |
This comment has been minimized.
This comment has been minimized.
|
Hi @kennytm and @ArazAbishov, apologies for the slow response, I found myself with little free time this week! Here's the current set of problem cases that I've discovered:
All of the cases ending in '. .' failed due to those not getting normalized away. Most of the UNC paths did not trip up |
pietroalbini
added
S-waiting-on-review
and removed
S-waiting-on-author
labels
Mar 5, 2018
This comment has been minimized.
This comment has been minimized.
kennytm
self-assigned this
Mar 6, 2018
This comment has been minimized.
This comment has been minimized.
|
@ThatsGobbles Hi sorry for long delay. I'm not totally familiar with Windows path, so perhaps @retep998 can give some more mentoring. (The failing test cases are in the source file already)
|
shepmaster
added
S-waiting-on-author
and removed
S-waiting-on-review
labels
Mar 18, 2018
This comment has been minimized.
This comment has been minimized.
|
Ping from triage, @ThatsGobbles ! You've got some feedback from @kennytm; will you be able to address it in the near future? |
This comment has been minimized.
This comment has been minimized.
|
Thank you so much for this PR @ThatsGobbles! Unfortunately, we haven't heard from you in a while, so I'm closing this to keep the list of PRs clean. If you have time to work on this again please reopen the pull request though! We will be happy to review the new changes. |
ThatsGobbles commentedJan 11, 2018
As per the discussion here: rust-lang/rfcs#2208
I found myself with a need to normalize file paths. By "normalize", I refer to the lexical cleanup of a path, following a similar algorithm as Python's os.path.normpath() and Go's filepath.Clean(). These in turn follow the methodology outlined in Rob Pike's paper: Lexical File Names in Plan 9.
I was able to write a method that works for my use case, and I felt it could be a helpful addition to stdlib! However, I am very new to both Rust and contributing to OSS projects. Please do let me know if there are any changes that could/should be made in those regards.