Repository navigation
chmod, chown, chgrp: skip entries removed during -R traversal - #16666
costajohnt wants to merge 3 commits into
Conversation
An entry listed in a directory but gone by the time it is stat-ed, changed or opened is now skipped silently, as GNU does. Other errors, a dangling symlink and a missing operand are still reported. Part of uutils#16644
| // Removed since the directory was listed: skip it, like GNU. | ||
| // Only a followed stat can also fail on a dangling symlink. | ||
| Err(err) | ||
| if err.kind() == std::io::ErrorKind::NotFound |
There was a problem hiding this comment.
Please don't sopecialize some specific errno. The issue mentioned ENOENT, but it is not ENOENT specific.
| ChmodError::PermissionDenied(entry_path.clone()) | ||
| } else { | ||
| ChmodError::CannotStat(entry_path.clone(), err) | ||
| }; |
There was a problem hiding this comment.
Previous code base is badly designed. We should use uucore::error::strip_errno(e), or we lost many errors.
| let bin = ts.bin_path.to_string_lossy().into_owned(); | ||
| let arg = String::from("0750"); | ||
| // Returns the status and stderr, minus strace's note on resolving `gone`. | ||
| let run = |error: &str, args: &[&str]| -> Option<(ExitStatus, String)> { |
There was a problem hiding this comment.
same strace runner copied in test_chmod, test_chown and test_chgrp, could it be a helper in tests/uutests?
| Ok(m) => m, | ||
| // Removed since the directory was listed: skip it, like GNU. | ||
| // Only a followed stat can also fail on a dangling symlink. | ||
| Err(e) |
There was a problem hiding this comment.
almost the same dangling symlink check as is_symlink in chmod.rs, could it be shared?
| Command::new("strace") | ||
| .args(["-qq", "-o", "/dev/null", "-P", "gone", "-e"]) | ||
| .arg(format!("inject=?chown,?lchown,fchownat:error={error}")) | ||
| .args([bin.as_str(), util_name!(), arg.as_str()]) |
There was a problem hiding this comment.
only the chown syscall is injected, the new skips on stat and open_subdir are not tested. please add a test for them
|
Binary size comparison: |
Move the strace runner duplicated in the chmod, chown and chgrp traversal tests into run_ucmd_with_strace_inject.
|
Good idea, done in 5e4d435: |
| args: &[&str], | ||
| ) -> Option<(ExitStatus, String)> { | ||
| Command::new("strace") | ||
| .args(["-qq", "-o", "/dev/null", "-P", path, "-e"]) |
There was a problem hiding this comment.
I think hardcoding some args is specialized to some specific usecase. We don't want to -o /dev/null -P path at many cases.
Rename run_ucmd_with_strace_inject to run_ucmd_with_strace and take the strace arguments as a slice, so the helper only runs the util under strace in the fixture dir and filters strace's own stderr lines. The chmod, chown and chgrp traversal tests now pass their -P and inject options themselves.
|
Good point, the helper was built around this one injection setup. It's now |
Merging this PR will degrade performance by 7.59%1 warning, 1 note
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
With
-R,chmod,chownandchgrpnow skip an entry that was listed in a directory but is gone by the time it is stat-ed, changed or opened, with no message and no effect on the exit status. This is the issue's repro: injecting ENOENT onfchmodat/fchownatfor one entry used to print "No such file or directory" and exit 1.Only the readdir entries inside the walk are affected. A missing operand and other errors (EIO, EACCES) are still reported. Where ENOENT can mean a dangling symlink (following with
-L, or-Hfor chown/chgrp), the entry is checked through the directory fd, and a dangling link is still reported as before.The new tests in
test_chmod.rs,test_chown.rsandtest_chgrp.rsuse strace fault injection the waytest_rm.rsdoes: ENOENT on one entry must be silent with exit 0, and EIO on the same entry must still be reported. They skip when strace can't inject.This covers chmod, chown and chgrp on Linux.
lsandduhave their own walkers and aren't changed here, and neither is the non-Linux chown/chgrp walker.Part of #16644