coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] dd: fix status=progress output for "infinite" xfer rates


From: Pádraig Brady
Subject: [PATCH] dd: fix status=progress output for "infinite" xfer rates
Date: Thu, 31 Dec 2015 18:20:44 +0000

* src/dd.c (print_xfer_stats): When the previous status=progress
output line contains "Infinity B/s" and the next does not
then the progress line would contain extraneous characters.
So output the "Clear to EOL" ANSI escape code to handle this edge case.
One can see "infinite" rates when the clock resolution is below
the (cached) data transfer time.
---
 src/dd.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/dd.c b/src/dd.c
index 870e938..9cdc635 100644
--- a/src/dd.c
+++ b/src/dd.c
@@ -766,6 +766,8 @@ print_xfer_stats (xtime_t progress_time)
   double delta_s;
   char const *bytes_per_second;
   size_t w_bytes_base = 0; /* auto for final stats.  */
+  bool inf_xfer = false; /* Used to output "clear to EOL" if needed.  */
+  static bool prev_inf_xfer = false;
 
   if (progress_time)
     {
@@ -799,6 +801,7 @@ print_xfer_stats (xtime_t progress_time)
     {
       delta_s = 0;
       bytes_per_second = _("Infinity B");
+      inf_xfer = true;
     }
 
   /* TRANSLATORS: The two instances of "s" in this string are the SI
@@ -813,9 +816,13 @@ print_xfer_stats (xtime_t progress_time)
      confusing in English.  */
   char const *time_fmt = _(", %g s, %s/s\n");
   if (progress_time)
-    time_fmt = _(", %.6f s, %s/s");  /* OK with '\r' as increasing width.  */
+    time_fmt = _(", %.6f s, %s/s");  /* OK with '\r', as increasing width.  */
   fprintf (stderr, time_fmt, delta_s, bytes_per_second);
 
+  if (progress_time && prev_inf_xfer && ! inf_xfer)
+    fputs ("\033[K", stderr);
+  prev_inf_xfer = inf_xfer;
+
   newline_pending = !!progress_time;
 }
 
-- 
2.5.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]