From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:470:142:3::10]:51151) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j5SKL-00079B-2j for guix-patches@gnu.org; Sat, 22 Feb 2020 05:48:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j5SKJ-0001aL-3P for guix-patches@gnu.org; Sat, 22 Feb 2020 05:48:04 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:42616) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j5SKI-0001a9-Jo for guix-patches@gnu.org; Sat, 22 Feb 2020 05:48:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1j5SKI-0003L6-GP for guix-patches@gnu.org; Sat, 22 Feb 2020 05:48:02 -0500 Subject: [bug#39734] [PATCH] scripts: Emit GC hint if free space is lower than absolute and relative threshold. Resent-Message-ID: Received: from eggs.gnu.org ([2001:470:142:3::10]:51057) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j5SJI-00072r-2w for guix-patches@gnu.org; Sat, 22 Feb 2020 05:47:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j5SJG-0000bQ-LG for guix-patches@gnu.org; Sat, 22 Feb 2020 05:46:59 -0500 Received: from relay4-d.mail.gandi.net ([217.70.183.196]:35741) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j5SJG-0000Xv-FY for guix-patches@gnu.org; Sat, 22 Feb 2020 05:46:58 -0500 Received: from bababa.home (lfbn-idf2-1-1315-147.w92-169.abo.wanadoo.fr [92.169.129.147]) (Authenticated sender: mail@ambrevar.xyz) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 9B4B2E0002 for ; Sat, 22 Feb 2020 10:46:53 +0000 (UTC) From: Pierre Neidhardt Date: Sat, 22 Feb 2020 11:46:53 +0100 Message-Id: <20200222104653.1324-1-mail@ambrevar.xyz> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: 39734@debbugs.gnu.org * 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