Skip to content

Comments

cp: preserve destination context for recursive permission-denied errors#11084

Open
jorgitin02 wants to merge 1 commit intouutils:mainfrom
jorgitin02:fix/9235-cp-recursive-perm-denied
Open

cp: preserve destination context for recursive permission-denied errors#11084
jorgitin02 wants to merge 1 commit intouutils:mainfrom
jorgitin02:fix/9235-cp-recursive-perm-denied

Conversation

@jorgitin02
Copy link

Fixes #9235.

Summary

Recursive cp currently rewrites any PermissionDenied during directory traversal
as:

cannot open '<source>' for reading: permission denied

That is incorrect when the failure is destination-side (for example, overwriting an
existing unwritable destination file).

This change preserves destination context for destination-side permission failures,
while keeping the source-read message for true source-read permission denial cases.

What changed

  • Updated recursive copy error handling in copydir:

@github-actions
Copy link

GNU testsuite comparison:

GNU test failed: tests/tee/tee. tests/tee/tee is passing on 'main'. Maybe you have to rebase?
Congrats! The gnu test tests/cut/bounded-memory is no longer failing!
Congrats! The gnu test tests/date/date-locale-hour is no longer failing!
Skip an intermittent issue tests/pr/bounded-memory (was skipped on 'main', now failing)

match err {
CpError::IoErrContext(e, _) if e.kind() == io::ErrorKind::PermissionDenied => {
CpError::IoErrContext(e, _)
if e.kind() == io::ErrorKind::PermissionDenied
Copy link
Contributor

Choose a reason for hiding this comment

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

it is starting to be a bit complex to understand, maybe move this into a function

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.

cp -r throws read permission error on unwritable destination file (mode: 440)

2 participants