chmod: report the real error when a target's metadata is inaccessible - #13637
chmod: report the real error when a target's metadata is inaccessible#136370xfandom wants to merge 1 commit into
Conversation
|
GNU testsuite comparison: |
|
a few jobs are failing |
chmod used Path::exists() to decide whether a target exists, but exists() returns false on any metadata error, so a file whose parent directory lacks search permission was reported as "No such file or directory" instead of "Permission denied". Use try_exists() to distinguish a genuine ENOENT from a permission error, matching GNU. Fixes uutils#9789.
44c1f3f to
7308279
Compare
Merging this PR will degrade performance by 3.49%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Simulation | du_wide_tree[(5000, 500)] |
22.2 ms | 23 ms | -3.49% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing 0xfandom:chmod-inaccessible-permission-denied (7308279) with main (0e4b3d5)2
Footnotes
-
46 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. ↩
-
No successful run was found on
main(d183a67) during the generation of this report, so 0e4b3d5 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩
Fixes #9789.
chmodusedPath::exists()to decide whether a target exists.Path::exists()returnsfalsefor any metadata access error, including permission errors, so a file whose parent directory lacks search permission was reported as:instead of GNU's:
This switches the non-recursive path to
Path::try_exists(), which returnsOk(false)only for a genuineENOENTandErr(..)for a permission error. A permission error is now reported via the existingChmodError::PermissionDeniedvariant, whose message already matches GNU. Any other unexpected metadata error falls through to the normal chmod attempt so it can surface a precise message.Added a regression test (
test_chmod_inaccessible_file_reports_permission_denied) for the non-recursive case; it fails on the oldPath::exists()code (prints "No such file or directory") and passes with the fix. The existing permission-denied tests only covered the recursive (-R) path.