mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
Merge pull request #4194 from jfinkels/dd-single-byte-written
dd: correct progress line if 1 byte written
This commit is contained in:
commit
c78e077ff2
1 changed files with 17 additions and 9 deletions
|
@ -151,20 +151,23 @@ impl ProgUpdate {
|
||||||
// If the number of bytes written is sufficiently large, then
|
// If the number of bytes written is sufficiently large, then
|
||||||
// print a more concise representation of the number, like
|
// print a more concise representation of the number, like
|
||||||
// "1.2 kB" and "1.0 KiB".
|
// "1.2 kB" and "1.0 KiB".
|
||||||
if btotal < 1000 {
|
match btotal {
|
||||||
write!(
|
1 => write!(
|
||||||
|
w,
|
||||||
|
"{}{} byte copied, {:.1} s, {}/s{}",
|
||||||
|
carriage_return, btotal, duration, transfer_rate, newline,
|
||||||
|
),
|
||||||
|
0..=999 => write!(
|
||||||
w,
|
w,
|
||||||
"{}{} bytes copied, {:.1} s, {}/s{}",
|
"{}{} bytes copied, {:.1} s, {}/s{}",
|
||||||
carriage_return, btotal, duration, transfer_rate, newline,
|
carriage_return, btotal, duration, transfer_rate, newline,
|
||||||
)
|
),
|
||||||
} else if btotal < 1024 {
|
1000..=1023 => write!(
|
||||||
write!(
|
|
||||||
w,
|
w,
|
||||||
"{}{} bytes ({}) copied, {:.1} s, {}/s{}",
|
"{}{} bytes ({}) copied, {:.1} s, {}/s{}",
|
||||||
carriage_return, btotal, btotal_metric, duration, transfer_rate, newline,
|
carriage_return, btotal, btotal_metric, duration, transfer_rate, newline,
|
||||||
)
|
),
|
||||||
} else {
|
_ => write!(
|
||||||
write!(
|
|
||||||
w,
|
w,
|
||||||
"{}{} bytes ({}, {}) copied, {:.1} s, {}/s{}",
|
"{}{} bytes ({}, {}) copied, {:.1} s, {}/s{}",
|
||||||
carriage_return,
|
carriage_return,
|
||||||
|
@ -174,7 +177,7 @@ impl ProgUpdate {
|
||||||
duration,
|
duration,
|
||||||
transfer_rate,
|
transfer_rate,
|
||||||
newline,
|
newline,
|
||||||
)
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -564,6 +567,11 @@ mod tests {
|
||||||
// The throughput still does not match GNU dd.
|
// The throughput still does not match GNU dd.
|
||||||
assert_eq!(cursor.get_ref(), b"0 bytes copied, 1.0 s, 0.0 B/s\n");
|
assert_eq!(cursor.get_ref(), b"0 bytes copied, 1.0 s, 0.0 B/s\n");
|
||||||
|
|
||||||
|
let prog_update = prog_update_write(1);
|
||||||
|
let mut cursor = Cursor::new(vec![]);
|
||||||
|
prog_update.write_prog_line(&mut cursor, rewrite).unwrap();
|
||||||
|
assert_eq!(cursor.get_ref(), b"1 byte copied, 1.0 s, 0.0 B/s\n");
|
||||||
|
|
||||||
let prog_update = prog_update_write(999);
|
let prog_update = prog_update_write(999);
|
||||||
let mut cursor = Cursor::new(vec![]);
|
let mut cursor = Cursor::new(vec![]);
|
||||||
prog_update.write_prog_line(&mut cursor, rewrite).unwrap();
|
prog_update.write_prog_line(&mut cursor, rewrite).unwrap();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue