Skip to content

cp: propagate the --attributes-only destination open error#12625

Open
leeewee wants to merge 1 commit into
uutils:mainfrom
leeewee:cp-fix-attributes-only-open-unwrap
Open

cp: propagate the --attributes-only destination open error#12625
leeewee wants to merge 1 commit into
uutils:mainfrom
leeewee:cp-fix-attributes-only-open-unwrap

Conversation

@leeewee
Copy link
Copy Markdown
Contributor

@leeewee leeewee commented Jun 5, 2026

Fixes #12624

cp --attributes-only SRC DEST aborted with a Result::unwrap() panic when opening the destination failed (e.g. EACCES on an unwritable parent, ENOTDIR on a non-directory parent): the CopyMode::AttrOnly branch unwrapped the open result.

Propagate the open error with the existing 'src' -> 'dest' context via CpError::IoErrContext, like the other I/O sites in handle_copy_mode, so cp reports the error and exits 1 instead of crashing. Adds a regression test.

`cp --attributes-only SRC DEST` aborted with a Result::unwrap panic when
opening DEST failed (e.g. EACCES on an unwritable parent, or ENOTDIR on a
non-directory parent). The CopyMode::AttrOnly branch of handle_copy_mode
opened the destination and `.unwrap()`ed the result.

Propagate the open error with the existing `'src' -> 'dest'` context via
`CpError::IoErrContext`, like the other I/O sites in this function, so cp
reports the error and exits 1 instead of crashing.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 5, 2026

GNU testsuite comparison:

Skipping an intermittent issue tests/date/date-locale-hour (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/tail/retry (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/dd/no-allocate is now passing!
Congrats! The gnu test tests/seq/seq-epipe is now passing!

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 panics (unwrap Err) on --attributes-only into an unwritable destination

1 participant