-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Use iterative algorithms for mkdir_recursive and rmdir_recursive #12573
Conversation
These functions should be renamed if they are not recursive anymore, the doc comments before them also. |
@adrientetar: I don't think the names correspond to their implementations, but rather their behaviour (making nested directories, etc.). |
Yes, they serve the same purposes as I voluntarily left the original functions names pending for discussion. |
let mut curpath = match path.is_absolute() { | ||
true => Path::new("/"), | ||
false => Path::new("./") | ||
}; |
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.
I've found recently that as soon as you look at a path you've probably forgotten one thing or another. This may need to change to something like path.root_path().unwrap_or(Path::new("."))
to take into account drives on windows.
cc @kballard, you know lots about windows paths.
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.
That's absolutely correct. That takes into account the multitude of possible path prefixes on Windows.
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.
I also wonder if this takes into account symlinks and whatnot.
Here are some corrections for the root problem and Still need to be worked on :
|
@lbonn, if you want, you can defer the semantics fixes until later. I think that the change to non-recursion is worth merging regardless of changing what exactly the function does. To that end, I would recommend dealing with the spatial complexity and using |
Nice. |
This one is more space efficient and uses However, it calls Also it looks like |
|
||
// delete all regular files in the way and push subdirs | ||
// on the stack | ||
for child in children.iter() { |
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.
If you use .move_iter()
here, the .clone()
will be unnecessary.
Thanks for the re-read, it should look better. This turned out to be a good learning exercice :). |
match unlink(&child) { | ||
Ok(()) => (), | ||
Err(ref e) if e.kind == io::FileNotFound => (), | ||
Err(e) => return Err(e) |
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.
I don't personally understand why io::FileNotFound
is ignored. Can you add a comment explaining why?
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.
I guess, because there is no harm done if the file you want to remove is not there in the first place. But i agree: this constellation/reasoning should be documented.
I would also like to see some tests for all the new functionality. I'm a little uncomfortable adding in the You'll find a bunch of tests at the end of this module, and if you wrap them in the |
It turns out the functions were not really tested, except for the somewhat odd Here are some tests which check for basic functionnality and ensure that symlinks to other directories are not explored during deletion. |
let testdir = tmpdir().join("d1/d2"); | ||
check!(mkdir_recursive(&testdir, io::UserRWX)); | ||
assert!(testdir.is_dir()) | ||
}) |
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.
This test should have tmpdir
alive for the entire test. Otherwise it leaves around temporary directories.
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.
Ah I see. This is pretty subtle because the test still passes.
This failed on windows, likely because |
Yes, it makes sense :). I'll try to set up a build on my windows machine and work on |
It's ok to ignore the tests on windows for now though. I had difficulty figuring out how to implement |
For now, the windows version uses stat, just as before. We should switch back to lstat as soon as rust-lang#12795 is closed.
The rmdir test is blocked by rust-lang#12795 on windows.
As mentioned in #6109, ```mkdir_recursive``` doesn't really need to use recursive calls, so here is an iterative version. The other points of the proposed overhaul (renaming and existing permissions) still need to be resolved. I also bundled an iterative ```rmdir_recursive```, for the same reason. Please do not hesitate to provide feedback on style as this is my first code change in rust.
internal: Split flyimport into its 3 applicable contexts
…ns-in-module-name-repetitions, r=Jarcho [`module_name_repetition`] Recognize common prepositions Fixes rust-lang#12544 changelog: [`module_name_repetition`]: don't report an item name if it consists only of a prefix from `allowed-prefixes` list and a module name (e.g. `AsFoo` in module `foo`). Prefixes allowed by default: [`to`, `from`, `into`, `as`, `try_into`, `try_from`]
As mentioned in #6109,
mkdir_recursive
doesn't really need to use recursive calls, so here is an iterative version.The other points of the proposed overhaul (renaming and existing permissions) still need to be resolved.
I also bundled an iterative
rmdir_recursive
, for the same reason.Please do not hesitate to provide feedback on style as this is my first code change in rust.