diff --git a/dev/src/uu_dd/progress.rs.html b/dev/src/uu_dd/progress.rs.html index 5e341fc15..84a52d0dc 100644 --- a/dev/src/uu_dd/progress.rs.html +++ b/dev/src/uu_dd/progress.rs.html @@ -631,6 +631,31 @@ 631 632 633 +634 +635 +636 +637 +638 +639 +640 +641 +642 +643 +644 +645 +646 +647 +648 +649 +650 +651 +652 +653 +654 +655 +656 +657 +658
// * This file is part of the uutils coreutils package.
// *
// * For the full copyright and license information, please view the LICENSE
@@ -646,6 +671,9 @@
use std::sync::mpsc;
use std::time::Duration;
+use uucore::error::UResult;
+use uucore::memo::sprintf;
+
use crate::numbers::{to_magnitude_and_suffix, SuffixType};
// On Linux, we register a signal handler that prints progress updates.
@@ -764,7 +792,7 @@
/// prog_update.write_prog_line(&mut cursor, rewrite).unwrap();
/// assert_eq!(cursor.get_ref(), b"0 bytes copied, 1.0 s, 0.0 B/s\n");
/// ```
- fn write_prog_line(&self, w: &mut impl Write, rewrite: bool) -> std::io::Result<()> {
+ fn write_prog_line(&self, w: &mut impl Write, rewrite: bool) -> UResult<()> {
// The total number of bytes written as a string, in SI and IEC format.
let btotal = self.write_stat.bytes_total;
let btotal_metric = to_magnitude_and_suffix(btotal, SuffixType::Si);
@@ -781,27 +809,31 @@
// (`\n`) at the end.
let (carriage_return, newline) = if rewrite { ("\r", "") } else { ("", "\n") };
+ // The duration should be formatted as in `printf %g`.
+ let duration_str = sprintf("%g", &[duration.to_string()])?;
+
// If the number of bytes written is sufficiently large, then
// print a more concise representation of the number, like
// "1.2 kB" and "1.0 KiB".
match btotal {
1 => write!(
w,
- "{carriage_return}{btotal} byte copied, {duration:.1} s, {transfer_rate}/s{newline}",
- ),
+ "{carriage_return}{btotal} byte copied, {duration_str} s, {transfer_rate}/s{newline}",
+ )?,
0..=999 => write!(
w,
- "{carriage_return}{btotal} bytes copied, {duration:.1} s, {transfer_rate}/s{newline}",
- ),
+ "{carriage_return}{btotal} bytes copied, {duration_str} s, {transfer_rate}/s{newline}",
+ )?,
1000..=1023 => write!(
w,
- "{carriage_return}{btotal} bytes ({btotal_metric}) copied, {duration:.1} s, {transfer_rate}/s{newline}",
- ),
+ "{carriage_return}{btotal} bytes ({btotal_metric}) copied, {duration_str} s, {transfer_rate}/s{newline}",
+ )?,
_ => write!(
w,
- "{carriage_return}{btotal} bytes ({btotal_metric}, {btotal_bin}) copied, {duration:.1} s, {transfer_rate}/s{newline}",
- ),
- }
+ "{carriage_return}{btotal} bytes ({btotal_metric}, {btotal_bin}) copied, {duration_str} s, {transfer_rate}/s{newline}",
+ )?,
+ };
+ Ok(())
}
/// Write all summary statistics.
@@ -833,7 +865,7 @@
/// assert_eq!(iter.next().unwrap(), b"");
/// assert!(iter.next().is_none());
/// ```
- fn write_transfer_stats(&self, w: &mut impl Write, new_line: bool) -> std::io::Result<()> {
+ fn write_transfer_stats(&self, w: &mut impl Write, new_line: bool) -> UResult<()> {
if new_line {
writeln!(w)?;
}
@@ -1129,6 +1161,15 @@
}
}
+ fn prog_update_duration(duration: Duration) -> ProgUpdate {
+ ProgUpdate {
+ read_stat: Default::default(),
+ write_stat: Default::default(),
+ duration: duration,
+ complete: false,
+ }
+ }
+
#[test]
fn test_read_stat_report() {
let read_stat = ReadStat::new(1, 2, 3);
@@ -1185,24 +1226,24 @@
// 0 bytes copied, 7.9151e-05 s, 0.0 kB/s
//
// 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 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");
+ assert_eq!(cursor.get_ref(), b"1 byte copied, 1 s, 0.0 B/s\n");
let prog_update = prog_update_write(999);
let mut cursor = Cursor::new(vec![]);
prog_update.write_prog_line(&mut cursor, rewrite).unwrap();
- assert_eq!(cursor.get_ref(), b"999 bytes copied, 1.0 s, 0.0 B/s\n");
+ assert_eq!(cursor.get_ref(), b"999 bytes copied, 1 s, 0.0 B/s\n");
let prog_update = prog_update_write(1000);
let mut cursor = Cursor::new(vec![]);
prog_update.write_prog_line(&mut cursor, rewrite).unwrap();
assert_eq!(
cursor.get_ref(),
- b"1000 bytes (1.0 kB) copied, 1.0 s, 1.0 kB/s\n"
+ b"1000 bytes (1.0 kB) copied, 1 s, 1.0 kB/s\n"
);
let prog_update = prog_update_write(1023);
@@ -1210,7 +1251,7 @@
prog_update.write_prog_line(&mut cursor, rewrite).unwrap();
assert_eq!(
cursor.get_ref(),
- b"1023 bytes (1.0 kB) copied, 1.0 s, 1.0 kB/s\n"
+ b"1023 bytes (1.0 kB) copied, 1 s, 1.0 kB/s\n"
);
let prog_update = prog_update_write(1024);
@@ -1218,7 +1259,7 @@
prog_update.write_prog_line(&mut cursor, rewrite).unwrap();
assert_eq!(
cursor.get_ref(),
- b"1024 bytes (1.0 kB, 1.0 KiB) copied, 1.0 s, 1.0 kB/s\n"
+ b"1024 bytes (1.0 kB, 1.0 KiB) copied, 1 s, 1.0 kB/s\n"
);
}
@@ -1237,7 +1278,7 @@
let mut iter = cursor.get_ref().split(|v| *v == b'\n');
assert_eq!(iter.next().unwrap(), b"0+0 records in");
assert_eq!(iter.next().unwrap(), b"0+0 records out");
- assert_eq!(iter.next().unwrap(), b"0 bytes copied, 1.0 s, 0.0 B/s");
+ assert_eq!(iter.next().unwrap(), b"0 bytes copied, 1 s, 0.0 B/s");
assert_eq!(iter.next().unwrap(), b"");
assert!(iter.next().is_none());
}
@@ -1256,13 +1297,22 @@
prog_update.write_prog_line(&mut cursor, rewrite).unwrap();
prog_update.write_transfer_stats(&mut cursor, true).unwrap();
let mut iter = cursor.get_ref().split(|v| *v == b'\n');
- assert_eq!(iter.next().unwrap(), b"\r0 bytes copied, 1.0 s, 0.0 B/s");
+ assert_eq!(iter.next().unwrap(), b"\r0 bytes copied, 1 s, 0.0 B/s");
assert_eq!(iter.next().unwrap(), b"0+0 records in");
assert_eq!(iter.next().unwrap(), b"0+0 records out");
- assert_eq!(iter.next().unwrap(), b"0 bytes copied, 1.0 s, 0.0 B/s");
+ assert_eq!(iter.next().unwrap(), b"0 bytes copied, 1 s, 0.0 B/s");
assert_eq!(iter.next().unwrap(), b"");
assert!(iter.next().is_none());
}
+
+ #[test]
+ fn test_duration_precision() {
+ let prog_update = prog_update_duration(Duration::from_nanos(123));
+ let mut cursor = Cursor::new(vec![]);
+ let rewrite = false;
+ prog_update.write_prog_line(&mut cursor, rewrite).unwrap();
+ assert_eq!(cursor.get_ref(), b"0 bytes copied, 1.23e-07 s, 0.0 B/s\n");
+ }
}