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 upFile Loop app example #239
Conversation
budziq
requested changes
Jul 14, 2017
|
Hi @Ophirr33 Thanks for the PR. As you've discovered you are reimplementing part of Here are some thoughts:
So with this simplified assumptions this could be made into a 4-5 liner. Also could you:
|
| [![same_file-badge]][same_file] [![cat-filesystem-badge]][cat-filesystem] | ||
|
|
||
| Use [`same-file::is_same_file`] to detect loops within a directory. | ||
| This manually iterates through the filesystem via the [`std::path`] module. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Hey @budziq, thanks for the feedback, I definitely misread what the example was going for. |
budziq
requested changes
Jul 14, 2017
|
Yeah lesson for me to be more explicit with descriptions. |
| let mut path_buf = path.to_path_buf(); | ||
| while path_buf.pop() { | ||
| if is_same_file(&path_buf, path)? { | ||
| return Ok(true); |
This comment has been minimized.
This comment has been minimized.
budziq
Jul 14, 2017
Collaborator
- the contains_loop tests only if the whole path is pointing to one of its ancestors while we would like to find all loops. calling it repeatedly on poped path segments will do the trick
- How about returning the result with optional looped path segments? (this might not come out that clean so I'll leave it up to you)
This comment has been minimized.
This comment has been minimized.
Ophirr33
Jul 14, 2017
Author
Contributor
Not 100% sure if I'm following. Basically it should detect a loop even when you don't specify the looped directory, right?
| // Check this path against all of its parents | ||
| fn contains_loop(path: &Path) -> io::Result<bool> { | ||
| let mut path_buf = path.to_path_buf(); |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@budziq It checks all paths and will return what paths it's looping between now. Let me know what else I can do |
budziq
requested changes
Jul 15, 2017
|
Excellent. One more tiny detail and we are good to merge |
|
|
||
| [![same_file-badge]][same_file] [![cat-filesystem-badge]][cat-filesystem] | ||
|
|
||
| Use [`same-file::is_same_file`] to detect loops for a given path. |
This comment has been minimized.
This comment has been minimized.
budziq
Jul 15, 2017
Collaborator
Please change the link same-file::is_same_file to same_file::is_same_file
This comment has been minimized.
This comment has been minimized.
|
@budziq Done! |
budziq
merged commit fad366b
into
rust-lang-nursery:master
Jul 15, 2017
1 check passed
This comment has been minimized.
This comment has been minimized.
|
@Ophirr33 Well done! |
Ophirr33 commentedJul 14, 2017
•
edited
This is a rough draft of the file loop example. I'd love some feedback on how to make it more concise. Right now there's a lot of boiler plate on iterating through the file system, and check parent paths. Though, the file system boilerplate could help make a better case for walkdir. @budziq , thanks for the tip on how to make a sym link loop. Fixes #207