aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxime Devos <maximedevos@telenet.be>2021-06-29 00:06:34 +0200
committerMathieu Othacehe <othacehe@gnu.org>2021-06-29 20:11:56 +0200
commit5ef96ecaaeeabd5500e406f0103ca52ec079fdb9 (patch)
tree66c81c89f388e744fc7d3cb4a6e45186ced62d37
parentfda0959a1426198f5588be691d1414807cb547cd (diff)
downloadguix-5ef96ecaaeeabd5500e406f0103ca52ec079fdb9.tar
guix-5ef96ecaaeeabd5500e406f0103ca52ec079fdb9.tar.gz
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>
-rw-r--r--guix/scripts/weather.scm17
1 files changed, 12 insertions, 5 deletions
diff --git a/guix/scripts/weather.scm b/guix/scripts/weather.scm
index 6d925d416c..06312d65a2 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)))))
;;;