Skip to content

cp: don't panic on verbose/debug write errors - #14031

Open
MsfPablo wants to merge 1 commit into
uutils:mainfrom
MsfPablo:fix-cp-verbose-write-error-10554
Open

cp: don't panic on verbose/debug write errors#14031
MsfPablo wants to merge 1 commit into
uutils:mainfrom
MsfPablo:fix-cp-verbose-write-error-10554

Conversation

@MsfPablo

Copy link
Copy Markdown
Contributor

Fixes #10554.

#13310 made the main 'src -> dest' verbose line non-panicking by buffering the write and surfacing the failure as a normal CpError::IoErrContext instead of panicking inside println!. Four remaining --verbose/--debug lines still used raw println!, so they still crashed when the stdout write failed — e.g. cp -vf /dev/null /tmp/a > /dev/full panics on the removed '<dest>' line, and cp --debug -n ... > /dev/full panics on the skipped '<dest>' line.

This converts the four remaining sites to a shared print_stdout_line helper that mirrors print_paths (BufWriter + writeln! + flush, error returned via ?):

  • cp-verbose-removed in delete_path (the -v "removed" line — the cp -vf /dev/null /tmp/a > /dev/full panics #10554 repro)
  • cp-debug-skipped in OverwriteMode::NoClobber::verify
  • the two skipped <dest> debug lines in handle_existing_dest / handle_copy_mode (UpdateMode::None)

Output and exit codes are unchanged on the happy path; only the failure mode changes (clean error + non-zero exit instead of a panic/abort), matching GNU cp which reports write error: ... and exits non-zero.

Two Linux-gated regression tests added next to test_cp_verbose_write_error_is_reported, covering the --remove-destination -v and --debug -n paths against /dev/full.

uutils#13310 made the main 'src -> dest' verbose line non-panicking by
buffering the write and returning an error, but the remaining
--verbose/--debug lines still used println!, which panics when the
stdout write fails (e.g. 'cp -vf ... > /dev/full' or a closed pipe).

Convert the four remaining raw println! sites -- the 'removed' verbose
line (delete_path), the NoClobber debug 'skipped' line, and the two
UpdateMode::None debug 'skipped' lines -- to a shared print_stdout_line
helper that mirrors print_paths: BufWriter + writeln + flush with the
write error surfaced via CpError::IoErrContext instead of a panic.

Fixes uutils#10554.
@HackingRepo

Copy link
Copy Markdown
Contributor

@MsfPablo already fixed

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 -vf /dev/null /tmp/a > /dev/full panics

2 participants