diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2019-04-06 22:29:18 +0200 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2019-04-10 17:09:47 +0200 |
| commit | bacf980c76c94e7bda86220ca4bf662d0e34a45a (patch) | |
| tree | cc5a7f09074b6b9d26e017d1a6d3c532722968cd | |
| parent | 72eda0624be89ed18302fd7d7f22976071ab020c (diff) | |
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.
| -rw-r--r-- | doc/guix.texi | 6 | ||||
| -rw-r--r-- | guix/scripts/gc.scm | 21 | ||||
| -rw-r--r-- | tests/guix-gc.sh | 6 |
3 files changed, 29 insertions, 4 deletions
diff --git a/doc/guix.texi b/doc/guix.texi index 2f9fcbe3bf8..2345617b2e8 100644 --- a/doc/guix.texi +++ b/doc/guix.texi | |||
| @@ -3385,7 +3385,7 @@ deleted. The set of garbage collector roots (``GC roots'' for short) | |||
| 3385 | includes default user profiles; by default, the symlinks under | 3385 | includes default user profiles; by default, the symlinks under |
| 3386 | @file{/var/guix/gcroots} represent these GC roots. New GC roots can be | 3386 | @file{/var/guix/gcroots} represent these GC roots. New GC roots can be |
| 3387 | added with @command{guix build --root}, for example (@pxref{Invoking | 3387 | added with @command{guix build --root}, for example (@pxref{Invoking |
| 3388 | guix build}). | 3388 | guix build}). The @command{guix gc --list-roots} command lists them. |
| 3389 | 3389 | ||
| 3390 | Prior to running @code{guix gc --collect-garbage} to make space, it is | 3390 | Prior to running @code{guix gc --collect-garbage} to make space, it is |
| 3391 | often useful to remove old generations from user profiles; that way, old | 3391 | 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 | |||
| 3451 | @option{--cache-failures} (@pxref{Invoking guix-daemon, | 3451 | @option{--cache-failures} (@pxref{Invoking guix-daemon, |
| 3452 | @option{--cache-failures}}). | 3452 | @option{--cache-failures}}). |
| 3453 | 3453 | ||
| 3454 | @item --list-roots | ||
| 3455 | List the GC roots owned by the user; when run as root, list @emph{all} the GC | ||
| 3456 | roots. | ||
| 3457 | |||
| 3454 | @item --clear-failures | 3458 | @item --clear-failures |
| 3455 | Remove the specified store items from the failed-build cache. | 3459 | Remove the specified store items from the failed-build cache. |
| 3456 | 3460 | ||
diff --git a/guix/scripts/gc.scm b/guix/scripts/gc.scm index 6f37b767ffa..2606e20deb1 100644 --- a/guix/scripts/gc.scm +++ b/guix/scripts/gc.scm | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | ;;; GNU Guix --- Functional package management for GNU | 1 | ;;; GNU Guix --- Functional package management for GNU |
| 2 | ;;; Copyright © 2012, 2013, 2015, 2016, 2017, 2018 Ludovic Courtès <ludo@gnu.org> | 2 | ;;; Copyright © 2012, 2013, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org> |
| 3 | ;;; | 3 | ;;; |
| 4 | ;;; This file is part of GNU Guix. | 4 | ;;; This file is part of GNU Guix. |
| 5 | ;;; | 5 | ;;; |
| @@ -20,6 +20,7 @@ | |||
| 20 | #:use-module (guix ui) | 20 | #:use-module (guix ui) |
| 21 | #:use-module (guix scripts) | 21 | #:use-module (guix scripts) |
| 22 | #:use-module (guix store) | 22 | #:use-module (guix store) |
| 23 | #:use-module (guix store roots) | ||
| 23 | #:autoload (guix build syscalls) (free-disk-space) | 24 | #:autoload (guix build syscalls) (free-disk-space) |
| 24 | #:use-module (ice-9 match) | 25 | #:use-module (ice-9 match) |
| 25 | #:use-module (ice-9 regex) | 26 | #:use-module (ice-9 regex) |
| @@ -49,6 +50,8 @@ Invoke the garbage collector.\n")) | |||
| 49 | (display (G_ " | 50 | (display (G_ " |
| 50 | -d, --delete attempt to delete PATHS")) | 51 | -d, --delete attempt to delete PATHS")) |
| 51 | (display (G_ " | 52 | (display (G_ " |
| 53 | --list-roots list the user's garbage collector roots")) | ||
| 54 | (display (G_ " | ||
| 52 | --optimize optimize the store by deduplicating identical files")) | 55 | --optimize optimize the store by deduplicating identical files")) |
| 53 | (display (G_ " | 56 | (display (G_ " |
| 54 | --list-dead list dead paths")) | 57 | --list-dead list dead paths")) |
| @@ -135,6 +138,10 @@ Invoke the garbage collector.\n")) | |||
| 135 | (alist-cons 'verify-options options | 138 | (alist-cons 'verify-options options |
| 136 | (alist-delete 'action | 139 | (alist-delete 'action |
| 137 | result)))))) | 140 | result)))))) |
| 141 | (option '("list-roots") #f #f | ||
| 142 | (lambda (opt name arg result) | ||
| 143 | (alist-cons 'action 'list-roots | ||
| 144 | (alist-delete 'action result)))) | ||
| 138 | (option '("list-dead") #f #f | 145 | (option '("list-dead") #f #f |
| 139 | (lambda (opt name arg result) | 146 | (lambda (opt name arg result) |
| 140 | (alist-cons 'action 'list-dead | 147 | (alist-cons 'action 'list-dead |
| @@ -205,6 +212,15 @@ Invoke the garbage collector.\n")) | |||
| 205 | (info (G_ "freeing ~h MiBs~%") (/ to-free 1024. 1024.)) | 212 | (info (G_ "freeing ~h MiBs~%") (/ to-free 1024. 1024.)) |
| 206 | (collect-garbage store to-free))))) | 213 | (collect-garbage store to-free))))) |
| 207 | 214 | ||
| 215 | (define (list-roots) | ||
| 216 | ;; List all the user-owned GC roots. | ||
| 217 | (let ((roots (filter (if (zero? (getuid)) (const #t) user-owned?) | ||
| 218 | (gc-roots)))) | ||
| 219 | (for-each (lambda (root) | ||
| 220 | (display root) | ||
| 221 | (newline)) | ||
| 222 | roots))) | ||
| 223 | |||
| 208 | (with-error-handling | 224 | (with-error-handling |
| 209 | (let* ((opts (parse-options)) | 225 | (let* ((opts (parse-options)) |
| 210 | (store (open-connection)) | 226 | (store (open-connection)) |
| @@ -238,6 +254,9 @@ Invoke the garbage collector.\n")) | |||
| 238 | (else | 254 | (else |
| 239 | (let-values (((paths freed) (collect-garbage store))) | 255 | (let-values (((paths freed) (collect-garbage store))) |
| 240 | (info (G_ "freed ~h MiBs~%") (/ freed 1024. 1024.))))))) | 256 | (info (G_ "freed ~h MiBs~%") (/ freed 1024. 1024.))))))) |
| 257 | ((list-roots) | ||
| 258 | (assert-no-extra-arguments) | ||
| 259 | (list-roots)) | ||
| 241 | ((delete) | 260 | ((delete) |
| 242 | (delete-paths store (map direct-store-path paths))) | 261 | (delete-paths store (map direct-store-path paths))) |
| 243 | ((list-references) | 262 | ((list-references) |
diff --git a/tests/guix-gc.sh b/tests/guix-gc.sh index ef2d9543b72..8284287730f 100644 --- a/tests/guix-gc.sh +++ b/tests/guix-gc.sh | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | # GNU Guix --- Functional package management for GNU | 1 | # GNU Guix --- Functional package management for GNU |
| 2 | # Copyright © 2013, 2015, 2017, 2018 Ludovic Courtès <ludo@gnu.org> | 2 | # Copyright © 2013, 2015, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org> |
| 3 | # | 3 | # |
| 4 | # This file is part of GNU Guix. | 4 | # This file is part of GNU Guix. |
| 5 | # | 5 | # |
| @@ -34,7 +34,7 @@ unset drv | |||
| 34 | unset out | 34 | unset out |
| 35 | 35 | ||
| 36 | # For some operations, passing extra arguments is an error. | 36 | # For some operations, passing extra arguments is an error. |
| 37 | for option in "" "-C 500M" "--verify" "--optimize" | 37 | for option in "" "-C 500M" "--verify" "--optimize" "--list-roots" |
| 38 | do | 38 | do |
| 39 | if guix gc $option whatever; then false; else true; fi | 39 | if guix gc $option whatever; then false; else true; fi |
| 40 | done | 40 | done |
| @@ -69,6 +69,8 @@ guix gc --delete "$drv" | |||
| 69 | drv="`guix build --root=guix-gc-root lsh -d`" | 69 | drv="`guix build --root=guix-gc-root lsh -d`" |
| 70 | test -f "$drv" && test -L guix-gc-root | 70 | test -f "$drv" && test -L guix-gc-root |
| 71 | 71 | ||
| 72 | guix gc --list-roots | grep "$PWD/guix-gc-root" | ||
| 73 | |||
| 72 | guix gc --list-live | grep "$drv" | 74 | guix gc --list-live | grep "$drv" |
| 73 | if guix gc --delete "$drv"; | 75 | if guix gc --delete "$drv"; |
| 74 | then false; else true; fi | 76 | then false; else true; fi |
