-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
rm: use recursive directory traversal with --recursive #7304
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
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
41122e0 to
ea9492f
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
07badcf to
cf49d13
Compare
This comment was marked as outdated.
This comment was marked as outdated.
cf49d13 to
fbd667b
Compare
Check the user write permission directly from the mode instead of using the `Permissions::readonly()` method. This seems to more closely match the behavior of GNU `rm`.
Change the implementation of `rm -r` so that it is explicitly recursive so that (1) there is one code path regardless of whether `--verbose` is given and (2) it is easier to be compatible with GNU `rm`. This change eliminates a dependency on the `walkdir` crate. Fixes uutils#7033, fixes uutils#7305, fixes uutils#7307.
fbd667b to
1606968
Compare
| // Special case: if we cannot access the metadata because the | ||
| // filename is too long, fall back to try | ||
| // `std::fs::remove_dir_all()`. | ||
| // | ||
| // TODO This is a temporary bandage; we shouldn't need to do this | ||
| // at all. Instead of using the full path like "x/y/z", which | ||
| // causes a `InvalidFilename` error when trying to access the file | ||
| // metadata, we should be able to use just the last part of the | ||
| // path, "z", and know that it is relative to the parent, "x/y". | ||
| if let Some(s) = path.to_str() { | ||
| if s.len() > 1000 { | ||
| match std::fs::remove_dir_all(path) { | ||
| Ok(_) => return false, | ||
| Err(e) => { | ||
| let e = e.map_err_context(|| format!("cannot remove {}", path.quote())); | ||
| show_error!("{e}"); | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
| } |
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 is here to pass the GNU test case tests/rm/deep-2.sh, where a very deep directory with a long name is created and then removed (like xxxx/xxxxx/xxxxx/...). The issue is that calling path.metadata() on a path that is too long returns an InvalidFilename error. Instead what we should do is use a relative path name and keep setting the working directory as we recurse. It must be possible because std::fs::remove_dir_all(path) seems to work on the very long path. I wasn't sure how to do that, so if someone knows how, I could update the code here. Otherwise, we can just leave this for now and fix it later.
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.
Similar issue with du in #7217
|
GNU testsuite comparison: |
|
kudos ! |
This includes the changes from #7306 and #7308.
Change the implementation of
rm -rso that it is explicitly recursiveso that (1) there is one code path regardless of whether
--verboseisgiven and (2) it is easier to be compatible with GNU
rm.This change eliminates a dependency on the
walkdircrate.Fixes #7033, fixes #7305.