unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
* [bug#39734] [PATCH] scripts: Emit GC hint if free space is lower than absolute and relative threshold.
@ 2020-02-22 10:46 Pierre Neidhardt
  2020-02-22 11:12 ` Ludovic Courtès
  0 siblings, 1 reply; 26+ messages in thread
From: Pierre Neidhardt @ 2020-02-22 10:46 UTC (permalink / raw)
  To: 39734

* guix/scripts.scm (%disk-space-warning-absolute): New variable.
(warn-about-disk-space): Test against %disk-space-warning-absolute.
Fix error in display-hint due to extraneous 'profile' argument.
---
 guix/scripts.scm | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/guix/scripts.scm b/guix/scripts.scm
index 77cbf12350..f8cce3a542 100644
--- a/guix/scripts.scm
+++ b/guix/scripts.scm
@@ -188,25 +188,35 @@ Show what and how will/would be built."
                     (#f        .05)               ;5%
                     (threshold (/ threshold 100.)))))
 
+(define %disk-space-warning-absolute
+  ;; The decimal number of GiB of free disk space below which a warning is
+  ;; emitted.
+  (make-parameter (match (and=> (getenv "GUIX_DISK_SPACE_WARNING_ABSOLUTE")
+                                string->number)
+                    (#f        17.0)
+                    (threshold threshold))))
+
 (define* (warn-about-disk-space #:optional profile
                                 #:key
-                                (threshold (%disk-space-warning)))
+                                (relative-threshold (%disk-space-warning))
+                                (absolute-threshold (%disk-space-warning-absolute)))
   "Display a hint about 'guix gc' if less than THRESHOLD of /gnu/store is
 available."
   (let* ((stats      (statfs (%store-prefix)))
          (block-size (file-system-block-size stats))
          (available  (* block-size (file-system-blocks-available stats)))
          (total      (* block-size (file-system-block-count stats)))
-         (ratio      (/ available total 1.)))
-    (when (< ratio threshold)
-      (warning (G_ "only ~,1f% of free space available on ~a~%")
-               (* ratio 100) (%store-prefix))
+         (relative-threshold-in-bytes (* total relative-threshold))
+         (absolute-threshold-in-bytes (* 1024 1024 1024 absolute-threshold)))
+    (when (< available (min relative-threshold-in-bytes
+                            absolute-threshold-in-bytes))
+      (warning (G_ "only ~,1f GiB of free space available on ~a~%")
+               available (%store-prefix))
       (display-hint (format #f (G_ "Consider deleting old profile
 generations and collecting garbage, along these lines:
 
 @example
 guix gc --delete-generations=1m
-@end example\n")
-                            profile)))))
+@end example\n"))))))
 
 ;;; scripts.scm ends here
-- 
2.25.0

^ permalink raw reply related	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2020-03-06  7:33 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-02-22 10:46 [bug#39734] [PATCH] scripts: Emit GC hint if free space is lower than absolute and relative threshold Pierre Neidhardt
2020-02-22 11:12 ` Ludovic Courtès
2020-02-22 11:39   ` Pierre Neidhardt
2020-02-23 11:46     ` Ludovic Courtès
2020-02-23 11:49       ` Pierre Neidhardt
2020-02-23 14:34         ` Ludovic Courtès
2020-02-23 14:41           ` Pierre Neidhardt
2020-02-23 16:09             ` Ludovic Courtès
2020-02-23 16:36               ` Pierre Neidhardt
2020-02-23 21:05               ` Pierre Neidhardt
2020-02-23 21:11                 ` Pierre Neidhardt
2020-02-24 10:21                   ` Ludovic Courtès
2020-02-24 10:26                     ` Pierre Neidhardt
2020-02-24 13:20                       ` Pierre Neidhardt
2020-02-24 21:08                         ` Ludovic Courtès
2020-02-25 10:22                           ` Pierre Neidhardt
2020-02-25 10:23                             ` Pierre Neidhardt
2020-02-27 23:19                               ` Ludovic Courtès
2020-02-28  7:17                                 ` Pierre Neidhardt
2020-03-05 16:29                                   ` Ludovic Courtès
2020-03-06  7:32                                     ` Pierre Neidhardt
2020-02-26 21:06                             ` bug#39734: " Ludovic Courtès
2020-02-24 13:20                       ` [bug#39734] " Pierre Neidhardt
2020-02-23 21:40                 ` Ludovic Courtès
2020-02-24  7:51                   ` Pierre Neidhardt
2020-02-24  7:52                   ` Pierre Neidhardt

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).