From 766c85fb5efa2ff2bd252c25f314925bc4730943 Mon Sep 17 00:00:00 2001 From: Jeffrey Finkelstein Date: Thu, 17 Feb 2022 22:35:30 -0500 Subject: [PATCH] dd: correct order and phrasing of truncated record Place the "truncated records" line below the "records out" line in the status report produced by `dd` and properly handle the singularization of the word "record" in the case of 1 truncated record. This matches the behavior of GNU `dd`. For example $ printf "ab" | dd cbs=1 conv=block status=noxfer > /dev/null 0+1 records in 0+1 records out 1 truncated record $ printf "ab\ncd\n" | dd cbs=1 conv=block status=noxfer > /dev/null 0+1 records in 0+1 records out 2 truncated records --- src/uu/dd/src/dd.rs | 8 +++++--- tests/by-util/test_dd.rs | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/uu/dd/src/dd.rs b/src/uu/dd/src/dd.rs index b24e18049..b38671a9a 100644 --- a/src/uu/dd/src/dd.rs +++ b/src/uu/dd/src/dd.rs @@ -779,13 +779,15 @@ fn print_io_lines(update: &ProgUpdate) { "{}+{} records in", update.read_stat.reads_complete, update.read_stat.reads_partial ); - if update.read_stat.records_truncated > 0 { - eprintln!("{} truncated records", update.read_stat.records_truncated); - } eprintln!( "{}+{} records out", update.write_stat.writes_complete, update.write_stat.writes_partial ); + match update.read_stat.records_truncated { + 0 => {} + 1 => eprintln!("1 truncated record"), + n => eprintln!("{} truncated records", n), + } } // Print the progress line of a status update: // bytes (, ) copied,