diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2013-02-27 23:16:00 +0100 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2013-02-27 23:16:00 +0100 |
| commit | ba8b732d209a891455ef08b81125796dab797435 (patch) | |
| tree | d2abdf96ed3798e9c046a847fa3eea04721ca32c | |
| parent | fae31edcec43c93a996a1872c68d1c540af0068f (diff) | |
guix gc: Add `--references' and `--referrers'.
* guix/scripts/gc.scm (show-help): Update.
(%options): Add `--references' and `--referrers'.
(guix-gc)[symlink-target, store-directory]: New procedures.
Handle the `list-references' and `list-referrers' actions.
* tests/guix-gc.sh: Add tests for `--references'.
* doc/guix.texi (Invoking guix gc): Document `--references' and
`--referrers'.
| -rw-r--r-- | doc/guix.texi | 12 | ||||
| -rw-r--r-- | guix/scripts/gc.scm | 56 | ||||
| -rw-r--r-- | tests/guix-gc.sh | 12 |
3 files changed, 73 insertions, 7 deletions
diff --git a/doc/guix.texi b/doc/guix.texi index 6a9ebab1f67..ec784ce3494 100644 --- a/doc/guix.texi +++ b/doc/guix.texi | |||
| @@ -657,6 +657,18 @@ store---i.e., files and directories no longer reachable from any root. | |||
| 657 | 657 | ||
| 658 | @item --list-live | 658 | @item --list-live |
| 659 | Show the list of live store files and directories. | 659 | Show the list of live store files and directories. |
| 660 | |||
| 661 | @end table | ||
| 662 | |||
| 663 | In addition, the references among existing store files can be queried: | ||
| 664 | |||
| 665 | @table @code | ||
| 666 | |||
| 667 | @item --references | ||
| 668 | @itemx --referrers | ||
| 669 | List the references (respectively, the referrers) of store files given | ||
| 670 | as arguments. | ||
| 671 | |||
| 660 | @end table | 672 | @end table |
| 661 | 673 | ||
| 662 | 674 | ||
diff --git a/guix/scripts/gc.scm b/guix/scripts/gc.scm index f2d2e17d4be..12d80fd1717 100644 --- a/guix/scripts/gc.scm +++ b/guix/scripts/gc.scm | |||
| @@ -20,6 +20,7 @@ | |||
| 20 | #:use-module (guix ui) | 20 | #:use-module (guix ui) |
| 21 | #:use-module (guix store) | 21 | #:use-module (guix store) |
| 22 | #:use-module (ice-9 match) | 22 | #:use-module (ice-9 match) |
| 23 | #:use-module (ice-9 regex) | ||
| 23 | #:use-module (srfi srfi-1) | 24 | #:use-module (srfi srfi-1) |
| 24 | #:use-module (srfi srfi-26) | 25 | #:use-module (srfi srfi-26) |
| 25 | #:use-module (srfi srfi-37) | 26 | #:use-module (srfi srfi-37) |
| @@ -48,6 +49,11 @@ Invoke the garbage collector.\n")) | |||
| 48 | --list-live list live paths")) | 49 | --list-live list live paths")) |
| 49 | (newline) | 50 | (newline) |
| 50 | (display (_ " | 51 | (display (_ " |
| 52 | --references list the references of PATHS")) | ||
| 53 | (display (_ " | ||
| 54 | --referrers list the referrers of PATHS")) | ||
| 55 | (newline) | ||
| 56 | (display (_ " | ||
| 51 | -h, --help display this help and exit")) | 57 | -h, --help display this help and exit")) |
| 52 | (display (_ " | 58 | (display (_ " |
| 53 | -V, --version display version information and exit")) | 59 | -V, --version display version information and exit")) |
| @@ -125,6 +131,14 @@ interpreted." | |||
| 125 | (option '("list-live") #f #f | 131 | (option '("list-live") #f #f |
| 126 | (lambda (opt name arg result) | 132 | (lambda (opt name arg result) |
| 127 | (alist-cons 'action 'list-live | 133 | (alist-cons 'action 'list-live |
| 134 | (alist-delete 'action result)))) | ||
| 135 | (option '("references") #f #f | ||
| 136 | (lambda (opt name arg result) | ||
| 137 | (alist-cons 'action 'list-references | ||
| 138 | (alist-delete 'action result)))) | ||
| 139 | (option '("referrers") #f #f | ||
| 140 | (lambda (opt name arg result) | ||
| 141 | (alist-cons 'action 'list-referrers | ||
| 128 | (alist-delete 'action result)))))) | 142 | (alist-delete 'action result)))))) |
| 129 | 143 | ||
| 130 | 144 | ||
| @@ -142,9 +156,37 @@ interpreted." | |||
| 142 | (alist-cons 'argument arg result)) | 156 | (alist-cons 'argument arg result)) |
| 143 | %default-options)) | 157 | %default-options)) |
| 144 | 158 | ||
| 159 | (define (symlink-target file) | ||
| 160 | (let ((s (false-if-exception (lstat file)))) | ||
| 161 | (if (and s (eq? 'symlink (stat:type s))) | ||
| 162 | (symlink-target (readlink file)) | ||
| 163 | file))) | ||
| 164 | |||
| 165 | (define (store-directory file) | ||
| 166 | ;; Return the store directory that holds FILE if it's in the store, | ||
| 167 | ;; otherwise return FILE. | ||
| 168 | (or (and=> (string-match (string-append "^" (regexp-quote (%store-prefix)) | ||
| 169 | "/([^/]+)") | ||
| 170 | file) | ||
| 171 | (compose (cut string-append (%store-prefix) "/" <>) | ||
| 172 | (cut match:substring <> 1))) | ||
| 173 | file)) | ||
| 174 | |||
| 145 | (with-error-handling | 175 | (with-error-handling |
| 146 | (let ((opts (parse-options)) | 176 | (let* ((opts (parse-options)) |
| 147 | (store (open-connection))) | 177 | (store (open-connection)) |
| 178 | (paths (filter-map (match-lambda | ||
| 179 | (('argument . arg) arg) | ||
| 180 | (_ #f)) | ||
| 181 | opts))) | ||
| 182 | (define (list-relatives relatives) | ||
| 183 | (for-each (compose (lambda (path) | ||
| 184 | (for-each (cut simple-format #t "~a~%" <>) | ||
| 185 | (relatives store path))) | ||
| 186 | store-directory | ||
| 187 | symlink-target) | ||
| 188 | paths)) | ||
| 189 | |||
| 148 | (case (assoc-ref opts 'action) | 190 | (case (assoc-ref opts 'action) |
| 149 | ((collect-garbage) | 191 | ((collect-garbage) |
| 150 | (let ((min-freed (assoc-ref opts 'min-freed))) | 192 | (let ((min-freed (assoc-ref opts 'min-freed))) |
| @@ -152,11 +194,11 @@ interpreted." | |||
| 152 | (collect-garbage store min-freed) | 194 | (collect-garbage store min-freed) |
| 153 | (collect-garbage store)))) | 195 | (collect-garbage store)))) |
| 154 | ((delete) | 196 | ((delete) |
| 155 | (let ((paths (filter-map (match-lambda | 197 | (delete-paths store paths)) |
| 156 | (('argument . arg) arg) | 198 | ((list-references) |
| 157 | (_ #f)) | 199 | (list-relatives references)) |
| 158 | opts))) | 200 | ((list-referrers) |
| 159 | (delete-paths store paths))) | 201 | (list-relatives referrers)) |
| 160 | ((list-dead) | 202 | ((list-dead) |
| 161 | (for-each (cut simple-format #t "~a~%" <>) | 203 | (for-each (cut simple-format #t "~a~%" <>) |
| 162 | (dead-paths store))) | 204 | (dead-paths store))) |
diff --git a/tests/guix-gc.sh b/tests/guix-gc.sh index a90d085ab2e..eac9d82e898 100644 --- a/tests/guix-gc.sh +++ b/tests/guix-gc.sh | |||
| @@ -25,6 +25,18 @@ guix gc --version | |||
| 25 | trap "rm -f guix-gc-root" EXIT | 25 | trap "rm -f guix-gc-root" EXIT |
| 26 | rm -f guix-gc-root | 26 | rm -f guix-gc-root |
| 27 | 27 | ||
| 28 | # Check the references of a .drv. | ||
| 29 | drv="`guix build guile-bootstrap -d`" | ||
| 30 | out="`guix build guile-bootstrap`" | ||
| 31 | test -f "$drv" && test -d "$out" | ||
| 32 | |||
| 33 | guix gc --references "$drv" | grep -e -bash | ||
| 34 | guix gc --references "$out" | ||
| 35 | guix gc --references "$out/bin/guile" | ||
| 36 | |||
| 37 | if guix gc --references /dev/null; | ||
| 38 | then false; else true; fi | ||
| 39 | |||
| 28 | # Add then reclaim a .drv file. | 40 | # Add then reclaim a .drv file. |
| 29 | drv="`guix build idutils -d`" | 41 | drv="`guix build idutils -d`" |
| 30 | test -f "$drv" | 42 | test -f "$drv" |
