scripts: Adjust disk-space warning functionality.

This is a followup to fb7eec3a84.

* guix/scripts.scm (warn-about-disk-space): Do not multiply
ABSOLUTE-THRESHOLD-IN-BYTES by 2^30.  Compare AVAILABLE to the max of
RELATIVE-THRESHOLD-IN-BYTES and ABSOLUTE-THRESHOLD-IN-BYTES, not the
min.  Display AVAILABLE divided by 2^30.
This commit is contained in:
Ludovic Courtès 2020-02-27 23:56:14 +01:00
parent 6b0653e7ec
commit 71c3c3df92
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5

View file

@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU ;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2013, 2014, 2015, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org> ;;; Copyright © 2013, 2014, 2015, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2014 Deck Pickard <deck.r.pickard@gmail.com> ;;; Copyright © 2014 Deck Pickard <deck.r.pickard@gmail.com>
;;; Copyright © 2015, 2016 Alex Kost <alezost@gmail.com> ;;; Copyright © 2015, 2016 Alex Kost <alezost@gmail.com>
;;; ;;;
@ -228,17 +228,19 @@ (define* (warn-about-disk-space #:optional profile
(thresholds (%disk-space-warning))) (thresholds (%disk-space-warning)))
"Display a hint about 'guix gc' if less than THRESHOLD of /gnu/store is "Display a hint about 'guix gc' if less than THRESHOLD of /gnu/store is
available. available.
THRESHOLD is a pair of (ABSOLUTE-THRESHOLD RELATIVE-THRESHOLD)." THRESHOLDS is a pair (ABSOLUTE-THRESHOLD . RELATIVE-THRESHOLD)."
(define GiB (expt 2 30))
(let* ((stats (statfs (%store-prefix))) (let* ((stats (statfs (%store-prefix)))
(block-size (file-system-block-size stats)) (block-size (file-system-block-size stats))
(available (* block-size (file-system-blocks-available stats))) (available (* block-size (file-system-blocks-available stats)))
(total (* block-size (file-system-block-count stats))) (total (* block-size (file-system-block-count stats)))
(relative-threshold-in-bytes (* total (cadr thresholds))) (relative-threshold-in-bytes (* total (cadr thresholds)))
(absolute-threshold-in-bytes (* 1024 1024 1024 (car thresholds)))) (absolute-threshold-in-bytes (car thresholds)))
(when (< available (min relative-threshold-in-bytes (when (< available (max relative-threshold-in-bytes
absolute-threshold-in-bytes)) absolute-threshold-in-bytes))
(warning (G_ "only ~,1f GiB of free space available on ~a~%") (warning (G_ "only ~,1f GiB of free space available on ~a~%")
available (%store-prefix)) (/ available 1. GiB) (%store-prefix))
(display-hint (format #f (G_ "Consider deleting old profile (display-hint (format #f (G_ "Consider deleting old profile
generations and collecting garbage, along these lines: generations and collecting garbage, along these lines: