Skip to content

chmod, chown, chgrp: skip entries removed during -R traversal - #16666

Open
costajohnt wants to merge 3 commits into
uutils:mainfrom
costajohnt:fix/traversal-missing-enoent
Open

costajohnt wants to merge 3 commits into
uutils:mainfrom
costajohnt:fix/traversal-missing-enoent

Conversation

@costajohnt

Copy link
Copy Markdown
Contributor

With -R, chmod, chown and chgrp now 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 on fchmodat / fchownat for 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 -H for 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.rs and test_chgrp.rs use strace fault injection the way test_rm.rs does: 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. ls and du have their own walkers and aren't changed here, and neither is the non-Linux chown/chgrp walker.

Part of #16644

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
Comment thread src/uu/chmod/src/chmod.rs
// 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

@oech3 oech3 Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't sopecialize some specific errno. The issue mentioned ENOENT, but it is not ENOENT specific.

Comment thread src/uu/chmod/src/chmod.rs
ChmodError::PermissionDenied(entry_path.clone())
} else {
ChmodError::CannotStat(entry_path.clone(), err)
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous code base is badly designed. We should use uucore::error::strip_errno(e), or we lost many errors.

Comment thread tests/by-util/test_chmod.rs Outdated
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)> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

almost the same dangling symlink check as is_symlink in chmod.rs, could it be shared?

Comment thread tests/by-util/test_chown.rs Outdated
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()])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only the chown syscall is injected, the new skips on stat and open_subdir are not tested. please add a test for them

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Binary size comparison:

Individual binary size comparison VS main (threshold: >=5% AND >=4 KB).

Total size of compared binaries: 155.48 MB (+100 KB, +0.06%)

Significant per-binary changes:
  env     1.20 MB ->    1.28 MB  (+80 KB, +6.51%)

Move the strace runner duplicated in the chmod, chown and chgrp
traversal tests into run_ucmd_with_strace_inject.
@costajohnt

Copy link
Copy Markdown
Contributor Author

Good idea, done in 5e4d435: run_ucmd_with_strace_inject in tests/uutests/src/lib/util.rs (Linux only, next to run_ucmd_as_root), and the three tests now just build their inject string and call it.

Comment thread tests/uutests/src/lib/util.rs Outdated
args: &[&str],
) -> Option<(ExitStatus, String)> {
Command::new("strace")
.args(["-qq", "-o", "/dev/null", "-P", path, "-e"])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@costajohnt

Copy link
Copy Markdown
Contributor Author

Good point, the helper was built around this one injection setup. It's now run_ucmd_with_strace, which just takes the strace args and the util args, so each test passes its own -o/-P/-e inject= options and the helper only handles spawning, cwd and the stderr filter.

@codspeed

codspeed Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will degrade performance by 7.59%

1 warning, 1 note

⚠️ 118 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

ℹ️ 1 benchmark has no flamegraph

The flamegraph wasn't generated: most of the time was spent in runtime internals, which would leave nothing useful to analyze.

See affected benchmarks

⚡ 1 improved benchmark
❌ 2 regressed benchmarks
✅ 262 untouched benchmarks
⏩ 218 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ CPU Simulation socket_addrs_direct[100000] 104.8 µs 132.5 µs -20.86%
❌ CPU Simulation hostname_ip_lookup[100000] 155.7 µs 185.6 µs -16.11%
⚡ CPU Simulation true_consecutive_calls 350.2 ns 294.7 ns +18.85%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing costajohnt:fix/traversal-missing-enoent (d6cbc62) with main (293a724)

Open in CodSpeed

Footnotes

  1. 218 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants