aboutsummaryrefslogtreecommitdiff
path: root/guix
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2019-04-06 22:29:18 +0200
committerLudovic Courtès <ludo@gnu.org>2019-04-10 17:09:47 +0200
commitbacf980c76c94e7bda86220ca4bf662d0e34a45a (patch)
treecc5a7f09074b6b9d26e017d1a6d3c532722968cd /guix
parent72eda0624be89ed18302fd7d7f22976071ab020c (diff)
downloadgnu-guix-bacf980c76c94e7bda86220ca4bf662d0e34a45a.tar
gnu-guix-bacf980c76c94e7bda86220ca4bf662d0e34a45a.tar.gz
guix gc: Add '--list-roots'.
* 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.
Diffstat (limited to 'guix')
-rw-r--r--guix/scripts/gc.scm21
1 files changed, 20 insertions, 1 deletions
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 <ludo@gnu.org>
+;;; Copyright © 2012, 2013, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
;;;
;;; 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)
@@ -49,6 +50,8 @@ Invoke the garbage collector.\n"))
(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_ "
--list-dead list dead paths"))
@@ -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)