Skip to content

Conversation

@majiayu000
Copy link

Summary

  • Use fs::metadata() instead of Path::exists() to distinguish between "file doesn't exist" and "permission denied" errors
  • Report appropriate error message based on the actual error kind

Root Cause

When a file exists but is inaccessible due to permission restrictions (e.g., chmod 755 locked/file where locked directory has no permissions), Path::exists() returns false for both non-existent files and inaccessible files. This caused chmod to incorrectly report "No such file or directory" instead of "Permission denied".

Changes

  • Modified Chmoder::chmod() to use fs::metadata() and check the error kind
  • Added test test_chmod_permission_denied_not_no_such_file to verify correct behavior

Test plan

  • Added new test case to verify the fix
  • All existing chmod tests pass (41 tests)

Fixes #9789

@github-actions
Copy link

GNU testsuite comparison:

Note: The gnu test tests/pr/pr-tests was skipped on 'main' but is now failing.

@majiayu000
Copy link
Author

The CI failure on tests/pr/pr-tests appears to be unrelated to this PR's changes.

This test was previously skipped on the main branch and is now failing - but my changes only modify chmod logic and don't touch the pr utility at all.

This looks like a flaky test or CI infrastructure issue rather than a regression caused by this PR.

All 41 existing chmod tests pass locally and the new test case validates the fix correctly. Would it be possible to re-run the CI or have a maintainer take a look at why this unrelated test started running?

@sylvestre
Copy link
Contributor

Could you please fix the conflict? Thanks

…tory

When a file exists but is inaccessible due to permission restrictions,
chmod was incorrectly reporting "No such file or directory" because
Path::exists() returns false for both non-existent files and
inaccessible files.

This change uses fs::metadata() to distinguish between these two cases
and reports the appropriate error message based on the actual error
kind (PermissionDenied vs NotFound).

Fixes uutils#9789

Signed-off-by: majiayu000 <[email protected]>
@majiayu000 majiayu000 force-pushed the fix/chmod-permission-denied-error-message branch from 76c83d0 to b15beab Compare December 29, 2025 02:22
@majiayu000
Copy link
Author

Rebased onto main and resolved the conflict. Ready for review.

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.

chmod: behavioral divergence from coreutils when the target file is not accessible

2 participants