[bug#33376,2/2] progress: Do not display the last 0B transfer when size is unknown.

Message ID 20181114101312.23617-2-clement@lassieur.org
State Accepted
Commit d827fd31ca19b2f81252cbe4e8bc982dd453a49a
Headers show
Series [bug#33376,1/2] progress: Fix crash because of division by zero. | expand

Checks

Context Check Description
cbaines/applying patch success Successfully applied

Commit Message

Clément Lassieur Nov. 14, 2018, 10:13 a.m. UTC
* guix/progress.scm (display-download-progress): Don't display anything when
both SIZE and TRANSFERRED are null.
---
 guix/progress.scm | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

Comments

Mathieu Othacehe Nov. 16, 2018, 1:43 p.m. UTC | #1
Hi Clément,

This patch and the previous one LGTM.

Thanks,

Mathieu
Clément Lassieur Nov. 16, 2018, 1:55 p.m. UTC | #2
Mathieu Othacehe <m.othacehe@gmail.com> writes:

> Hi Clément,
>
> This patch and the previous one LGTM.

Pushed, thank you for reviewing!

Patch

diff --git a/guix/progress.scm b/guix/progress.scm
index 7a25f11bd..65080bcf2 100644
--- a/guix/progress.scm
+++ b/guix/progress.scm
@@ -212,17 +212,20 @@  throughput."
                                     (current-terminal-columns))
                  log-port)
         (force-output log-port))
-      (let* ((throughput (/ transferred elapsed))
-             (left       (format #f " ~a" file))
-             (right      (format #f "~a/s ~a | ~a transferred"
-                                 (byte-count->string throughput)
-                                 (seconds->string elapsed)
-                                 (byte-count->string transferred))))
-        (erase-current-line log-port)
-        (display (string-pad-middle left right
-                                    (current-terminal-columns))
-                 log-port)
-        (force-output log-port))))
+      ;; If we don't know the total size, the last transfer will have a 0B
+      ;; size.  Don't display it.
+      (unless (zero? transferred)
+        (let* ((throughput (/ transferred elapsed))
+               (left       (format #f " ~a" file))
+               (right      (format #f "~a/s ~a | ~a transferred"
+                                   (byte-count->string throughput)
+                                   (seconds->string elapsed)
+                                   (byte-count->string transferred))))
+          (erase-current-line log-port)
+          (display (string-pad-middle left right
+                                      (current-terminal-columns))
+                   log-port)
+          (force-output log-port)))))
 
 (define %progress-interval
   ;; Default interval between subsequent outputs for rate-limited displays.