From patchwork Sat Feb 22 10:46:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Neidhardt X-Patchwork-Id: 20364 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id C9DED27BBEA; Sat, 22 Feb 2020 10:48:11 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTP id 9BD4727BBE4 for ; Sat, 22 Feb 2020 10:48:11 +0000 (GMT) Received: from localhost ([::1]:41262 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j5SKR-00079I-6N for patchwork@mira.cbaines.net; Sat, 22 Feb 2020 05:48:11 -0500 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 X-Loop: help-debbugs@gnu.org Subject: [bug#39734] [PATCH] scripts: Emit GC hint if free space is lower than absolute and relative threshold. Resent-From: Pierre Neidhardt Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 22 Feb 2020 10:48:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 39734 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 39734@debbugs.gnu.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.158236842312760 (code B ref -1); Sat, 22 Feb 2020 10:48:02 +0000 Received: (at submit) by debbugs.gnu.org; 22 Feb 2020 10:47:03 +0000 Received: from localhost ([127.0.0.1]:48589 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1j5SJL-0003Jk-6t for submit@debbugs.gnu.org; Sat, 22 Feb 2020 05:47:03 -0500 Received: from lists.gnu.org ([209.51.188.17]:59062) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1j5SJJ-0003JL-6i for submit@debbugs.gnu.org; Sat, 22 Feb 2020 05:47:01 -0500 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 X-Originating-IP: 92.169.129.147 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> X-Mailer: git-send-email 2.25.0 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * 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