cp: don't panic on verbose/debug write errors - #14031
Open
MsfPablo wants to merge 1 commit into
Open
Conversation
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.
Contributor
|
@MsfPablo already fixed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #10554.
#13310 made the main
'src -> dest'verbose line non-panicking by buffering the write and surfacing the failure as a normalCpError::IoErrContextinstead of panicking insideprintln!. Four remaining--verbose/--debuglines still used rawprintln!, so they still crashed when the stdout write failed — e.g.cp -vf /dev/null /tmp/a > /dev/fullpanics on theremoved '<dest>'line, andcp --debug -n ... > /dev/fullpanics on theskipped '<dest>'line.This converts the four remaining sites to a shared
print_stdout_linehelper that mirrorsprint_paths(BufWriter+writeln!+flush, error returned via?):cp-verbose-removedindelete_path(the-v"removed" line — the cp -vf /dev/null /tmp/a > /dev/full panics #10554 repro)cp-debug-skippedinOverwriteMode::NoClobber::verifyskipped <dest>debug lines inhandle_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
cpwhich reportswrite error: ...and exits non-zero.Two Linux-gated regression tests added next to
test_cp_verbose_write_error_is_reported, covering the--remove-destination -vand--debug -npaths against/dev/full.