guix-commits
[Top][All Lists]
Advanced

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

branch master updated: weather: Handle zero requested store items gracef


From: guix-commits
Subject: branch master updated: weather: Handle zero requested store items gracefully.
Date: Tue, 29 Jun 2021 14:21:53 -0400

This is an automated email from the git hooks/post-receive script.

mothacehe pushed a commit to branch master
in repository guix.

The following commit(s) were added to refs/heads/master by this push:
     new 5ef96ec  weather: Handle zero requested store items gracefully.
5ef96ec is described below

commit 5ef96ecaaeeabd5500e406f0103ca52ec079fdb9
Author: Maxime Devos <maximedevos@telenet.be>
AuthorDate: Tue Jun 29 00:06:34 2021 +0200

    weather: Handle zero requested store items gracefully.
    
    This can happen if the weather information of a package
    is requested for an unsupported system.  For example,
    try "guix weather icecat --system=aarch64-linux".
    
    * guix/scripts/weather.scm
      (report-server-coverage): Do not divide by zero when zero
      store items are requested from a server.
    
    Fixes: <https://issues.guix.gnu.org/49263>
    Reported-By: Jack Hill <jackhill@jackhill.us>
    Signed-off-by: Mathieu Othacehe <othacehe@gnu.org>
---
 guix/scripts/weather.scm | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/guix/scripts/weather.scm b/guix/scripts/weather.scm
index 6d925d4..06312d6 100644
--- a/guix/scripts/weather.scm
+++ b/guix/scripts/weather.scm
@@ -3,6 +3,7 @@
 ;;; Copyright © 2017 Ricardo Wurmus <rekado@elephly.net>
 ;;; Copyright © 2018 Kyle Meyer <kyle@kyleam.com>
 ;;; Copyright © 2020 Simon Tournier <zimon.toutoune@gmail.com>
+;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -185,9 +186,12 @@ or #f if it could not be determined."
                                  #:key display-missing?)
   "Report the subset of ITEMS available as substitutes on SERVER.
 When DISPLAY-MISSING? is true, display the list of missing substitutes.
-Return the coverage ratio, an exact number between 0 and 1."
+Return the coverage ratio, an exact number between 0 and 1.
+In case ITEMS is an empty list, return 1 instead."
   (define MiB (* (expt 2 20) 1.))
 
+  ;; TRANSLATORS: it is quite possible zero store items are
+  ;; looked for.
   (format #t (G_ "looking for ~h store items on ~a...~%")
           (length items) server)
 
@@ -208,9 +212,10 @@ Return the coverage ratio, an exact number between 0 and 
1."
                                  narinfos))
           (time      (+ (time-second time)
                         (/ (time-nanosecond time) 1e9))))
-      (format #t (G_ "  ~,1f% substitutes available (~h out of ~h)~%")
-              (* 100. (/ obtained requested 1.))
-              obtained requested)
+      (when (> requested 0)
+        (format #t (G_ "  ~,1f% substitutes available (~h out of ~h)~%")
+                (* 100. (/ obtained requested 1.))
+                obtained requested))
       (let ((total (/ (reduce + 0 sizes) MiB)))
         (match (length sizes)
           ((? zero?)
@@ -299,7 +304,9 @@ are queued~%")
 
       ;; Return the coverage ratio.
       (let ((total (length items)))
-        (/ (- total (length missing)) total)))))
+        (if (> total 0)
+            (/ (- total (length missing)) total)
+            1)))))
 
 
 ;;;



reply via email to

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