From patchwork Sat Apr 6 21:31:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 3238 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 7A08916E19; Sat, 6 Apr 2019 22:32:10 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTP id DD11A16DE8 for ; Sat, 6 Apr 2019 22:32:09 +0100 (BST) Received: from localhost ([127.0.0.1]:59253 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hCsv3-0006X2-FO for patchwork@mira.cbaines.net; Sat, 06 Apr 2019 17:32:09 -0400 Received: from eggs.gnu.org ([209.51.188.92]:37333) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hCsuz-0006VE-PJ for guix-patches@gnu.org; Sat, 06 Apr 2019 17:32:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hCsuy-0004gv-El for guix-patches@gnu.org; Sat, 06 Apr 2019 17:32:05 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:33986) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hCsux-0004g5-8X for guix-patches@gnu.org; Sat, 06 Apr 2019 17:32:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hCsux-0005ES-2E for guix-patches@gnu.org; Sat, 06 Apr 2019 17:32:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#35176] [PATCH 2/5] guix gc: Add '--list-roots'. Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 06 Apr 2019 21:32:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 35176 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 35176@debbugs.gnu.org Received: via spool by 35176-submit@debbugs.gnu.org id=B35176.155458630120058 (code B ref 35176); Sat, 06 Apr 2019 21:32:03 +0000 Received: (at 35176) by debbugs.gnu.org; 6 Apr 2019 21:31:41 +0000 Received: from localhost ([127.0.0.1]:47523 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hCsua-0005DP-Eu for submit@debbugs.gnu.org; Sat, 06 Apr 2019 17:31:40 -0400 Received: from eggs.gnu.org ([209.51.188.92]:51018) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hCsuW-0005Ch-BE for 35176@debbugs.gnu.org; Sat, 06 Apr 2019 17:31:36 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:46369) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hCsuR-0004O9-3p; Sat, 06 Apr 2019 17:31:31 -0400 Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=50434 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1hCsuQ-0002OK-Kz; Sat, 06 Apr 2019 17:31:30 -0400 From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Sat, 6 Apr 2019 23:31:20 +0200 Message-Id: <20190406213123.27164-2-ludo@gnu.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190406213123.27164-1-ludo@gnu.org> References: <20190406213123.27164-1-ludo@gnu.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] 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/gc.scm (show-help, %options): Add '--list-roots'. (guix-gc)[list-roots]: New procedure. Handle '--list-roots'. * tests/guix-gc.sh: Test it. * doc/guix.texi (Invoking guix gc): Document it. --- doc/guix.texi | 6 +++++- guix/scripts/gc.scm | 21 ++++++++++++++++++++- tests/guix-gc.sh | 6 ++++-- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 1c82579afc..75ab2fe4f5 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -3385,7 +3385,7 @@ deleted. The set of garbage collector roots (``GC roots'' for short) includes default user profiles; by default, the symlinks under @file{/var/guix/gcroots} represent these GC roots. New GC roots can be added with @command{guix build --root}, for example (@pxref{Invoking -guix build}). +guix build}). The @command{guix gc --list-roots} command lists them. Prior to running @code{guix gc --collect-garbage} to make space, it is often useful to remove old generations from user profiles; that way, old @@ -3451,6 +3451,10 @@ This prints nothing unless the daemon was started with @option{--cache-failures} (@pxref{Invoking guix-daemon, @option{--cache-failures}}). +@item --list-roots +List the GC roots owned by the user; when run as root, list @emph{all} the GC +roots. + @item --clear-failures Remove the specified store items from the failed-build cache. diff --git a/guix/scripts/gc.scm b/guix/scripts/gc.scm index 6f37b767ff..2606e20deb 100644 --- a/guix/scripts/gc.scm +++ b/guix/scripts/gc.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2012, 2013, 2015, 2016, 2017, 2018 Ludovic Courtès +;;; Copyright © 2012, 2013, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès ;;; ;;; This file is part of GNU Guix. ;;; @@ -20,6 +20,7 @@ #:use-module (guix ui) #:use-module (guix scripts) #:use-module (guix store) + #:use-module (guix store roots) #:autoload (guix build syscalls) (free-disk-space) #:use-module (ice-9 match) #:use-module (ice-9 regex) @@ -48,6 +49,8 @@ Invoke the garbage collector.\n")) -F, --free-space=FREE attempt to reach FREE available space in the store")) (display (G_ " -d, --delete attempt to delete PATHS")) + (display (G_ " + --list-roots list the user's garbage collector roots")) (display (G_ " --optimize optimize the store by deduplicating identical files")) (display (G_ " @@ -135,6 +138,10 @@ Invoke the garbage collector.\n")) (alist-cons 'verify-options options (alist-delete 'action result)))))) + (option '("list-roots") #f #f + (lambda (opt name arg result) + (alist-cons 'action 'list-roots + (alist-delete 'action result)))) (option '("list-dead") #f #f (lambda (opt name arg result) (alist-cons 'action 'list-dead @@ -205,6 +212,15 @@ Invoke the garbage collector.\n")) (info (G_ "freeing ~h MiBs~%") (/ to-free 1024. 1024.)) (collect-garbage store to-free))))) + (define (list-roots) + ;; List all the user-owned GC roots. + (let ((roots (filter (if (zero? (getuid)) (const #t) user-owned?) + (gc-roots)))) + (for-each (lambda (root) + (display root) + (newline)) + roots))) + (with-error-handling (let* ((opts (parse-options)) (store (open-connection)) @@ -238,6 +254,9 @@ Invoke the garbage collector.\n")) (else (let-values (((paths freed) (collect-garbage store))) (info (G_ "freed ~h MiBs~%") (/ freed 1024. 1024.))))))) + ((list-roots) + (assert-no-extra-arguments) + (list-roots)) ((delete) (delete-paths store (map direct-store-path paths))) ((list-references) diff --git a/tests/guix-gc.sh b/tests/guix-gc.sh index ef2d9543b7..8284287730 100644 --- a/tests/guix-gc.sh +++ b/tests/guix-gc.sh @@ -1,5 +1,5 @@ # GNU Guix --- Functional package management for GNU -# Copyright © 2013, 2015, 2017, 2018 Ludovic Courtès +# Copyright © 2013, 2015, 2017, 2018, 2019 Ludovic Courtès # # This file is part of GNU Guix. # @@ -34,7 +34,7 @@ unset drv unset out # For some operations, passing extra arguments is an error. -for option in "" "-C 500M" "--verify" "--optimize" +for option in "" "-C 500M" "--verify" "--optimize" "--list-roots" do if guix gc $option whatever; then false; else true; fi done @@ -69,6 +69,8 @@ guix gc --delete "$drv" drv="`guix build --root=guix-gc-root lsh -d`" test -f "$drv" && test -L guix-gc-root +guix gc --list-roots | grep "$PWD/guix-gc-root" + guix gc --list-live | grep "$drv" if guix gc --delete "$drv"; then false; else true; fi