From 38d27786086ff2b8d1325b1c0090ccff3745adfc Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Tue, 19 May 2015 09:59:45 +0200 Subject: guix gc: Add '--optimize'. * guix/scripts/gc.scm (show-help, %options): Add --optimize. (guix-gc): Handle it. --- guix/scripts/gc.scm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'guix/scripts/gc.scm') diff --git a/guix/scripts/gc.scm b/guix/scripts/gc.scm index ed16cab8f9..4bae65a1ec 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 Ludovic Courtès +;;; Copyright © 2012, 2013, 2015 Ludovic Courtès ;;; ;;; This file is part of GNU Guix. ;;; @@ -43,6 +43,8 @@ (define (show-help) collect at least MIN bytes of garbage")) (display (_ " -d, --delete attempt to delete PATHS")) + (display (_ " + --optimize optimize the store by deduplicating identical files")) (display (_ " --list-dead list dead paths")) (display (_ " @@ -88,6 +90,10 @@ (define %options (lambda (opt name arg result) (alist-cons 'action 'delete (alist-delete 'action result)))) + (option '("optimize") #f #f + (lambda (opt name arg result) + (alist-cons 'action 'optimize + (alist-delete 'action result)))) (option '("list-dead") #f #f (lambda (opt name arg result) (alist-cons 'action 'list-dead @@ -169,6 +175,8 @@ (define (list-relatives relatives) (list-relatives requisites)) ((list-referrers) (list-relatives referrers)) + ((optimize) + (optimize-store store)) ((list-dead) (for-each (cut simple-format #t "~a~%" <>) (dead-paths store))) -- cgit v1.2.3 From cdb5b075d545dd4e0b2a03bdc62fa0d1f6e00fc3 Mon Sep 17 00:00:00 2001 From: Cyrill Schenkel Date: Sun, 24 May 2015 14:04:15 +0200 Subject: gc: ignore trailing slash or subdirectories for `guix gc -d' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes . * guix/scripts/gc.scm (guix-gc): Convert paths to direct store paths. * guix/store.scm (direct-store-path): Get rid of subdirectories in store path. * tests/guix-gc.sh: New tests. Co-authored-by: Ludovic Courtès --- guix/scripts/gc.scm | 2 +- guix/store.scm | 10 ++++++++++ tests/guix-gc.sh | 20 ++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) (limited to 'guix/scripts/gc.scm') diff --git a/guix/scripts/gc.scm b/guix/scripts/gc.scm index 4bae65a1ec..a250cdc197 100644 --- a/guix/scripts/gc.scm +++ b/guix/scripts/gc.scm @@ -168,7 +168,7 @@ (define (list-relatives relatives) (collect-garbage store min-freed) (collect-garbage store)))) ((delete) - (delete-paths store paths)) + (delete-paths store (map direct-store-path paths))) ((list-references) (list-relatives references)) ((list-requisites) diff --git a/guix/store.scm b/guix/store.scm index fc2f8d92ca..8905a5a558 100644 --- a/guix/store.scm +++ b/guix/store.scm @@ -121,6 +121,7 @@ (define-module (guix store) derivation-path? store-path-package-name store-path-hash-part + direct-store-path log-file)) (define %protocol-version #x10c) @@ -1012,6 +1013,15 @@ (define (direct-store-path? path) (let ((len (+ 1 (string-length (%store-prefix))))) (not (string-index (substring path len) #\/))))) +(define (direct-store-path path) + "Return the direct store path part of PATH, stripping components after +'/gnu/store/xxxx-foo'." + (let ((prefix-length (+ (string-length (%store-prefix)) 35))) + (if (> (string-length path) prefix-length) + (let ((slash (string-index path #\/ prefix-length))) + (if slash (string-take path slash) path)) + path))) + (define (derivation-path? path) "Return #t if PATH is a derivation path." (and (store-path? path) (string-suffix? ".drv" path))) diff --git a/tests/guix-gc.sh b/tests/guix-gc.sh index eac9d82e89..c1eb66cef5 100644 --- a/tests/guix-gc.sh +++ b/tests/guix-gc.sh @@ -64,3 +64,23 @@ guix gc -C 1KiB # Check trivial error cases. if guix gc --delete /dev/null; then false; else true; fi + +# Bug #19757 +out="`guix build guile-bootstrap`" +test -d "$out" + +guix gc --delete "$out" + +! test -d "$out" + +out="`guix build guile-bootstrap`" +test -d "$out" + +guix gc --delete "$out/" + +! test -d "$out" + +out="`guix build guile-bootstrap`" +test -d "$out" + +guix gc --delete "$out/bin/guile" -- cgit v1.2.3 From 7770aafc7561897ff1d3c706420f76843c5182c0 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Sat, 6 Jun 2015 18:56:04 +0200 Subject: guix gc: Add '--verify'. * guix/scripts/gc.scm (show-help, %options): Add --verify. (guix-gc): Handle it. * doc/guix.texi (Invoking guix gc): Document --verify, and move --optimize description right below it. --- doc/guix.texi | 57 +++++++++++++++++++++++++++++++++++++++++------------ guix/scripts/gc.scm | 22 +++++++++++++++++++++ 2 files changed, 66 insertions(+), 13 deletions(-) (limited to 'guix/scripts/gc.scm') diff --git a/doc/guix.texi b/doc/guix.texi index f8da9c1224..c102746636 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -1541,8 +1541,9 @@ is achieved by running @code{guix package --delete-generations} The @command{guix gc} command has three modes of operation: it can be used to garbage-collect any dead files (the default), to delete specific -files (the @code{--delete} option), or to print garbage-collector -information. The available options are listed below: +files (the @code{--delete} option), to print garbage-collector +information, or for more advanced queries. The garbage collection +options are as follows: @table @code @item --collect-garbage[=@var{min}] @@ -1564,17 +1565,6 @@ Attempt to delete all the store files and directories specified as arguments. This fails if some of the files are not in the store, or if they are still live. -@item --optimize -@cindex deduplication -Optimize the store by hard-linking identical files---this is -@dfn{deduplication}. - -The daemon performs deduplication after each successful build or archive -import, unless it was started with @code{--disable-deduplication} -(@pxref{Invoking guix-daemon, @code{--disable-deduplication}}). Thus, -this option is primarily useful when the daemon was running with -@code{--disable-deduplication}. - @item --list-dead Show the list of dead files and directories still present in the store---i.e., files and directories no longer reachable from any root. @@ -1602,6 +1592,47 @@ of these, recursively. In other words, the returned list is the @end table +Lastly, the following options allow you to check the integrity of the +store and to control disk usage. + +@table @option + +@item --verify[=@var{options}] +@cindex integrity, of the store +@cindex integrity checking +Verify the integrity of the store. + +By default, make sure that all the store items marked as valid in the +daemon's database actually exist in @file{/gnu/store}. + +When provided, @var{options} must a comma-separated list containing one +or more of @code{contents} and @code{repair}. + +When passing @option{--verify=contents}, the daemon will compute the +content hash of each store item and compare it against its hash in the +database. Hash mismatches are reported as data corruptions. Because it +traverses @emph{all the files in the store}, this command can take a +long time, especially on systems with a slow disk drive. + +@cindex repairing the store +Using @option{--verify=repair} or @option{--verify=contents,repair} +causes the daemon to try to repair corrupt store items by fetching +substitutes for them (@pxref{Substitutes}). Because repairing is not +atomic, and thus potentially dangerous, it is available only to the +system administrator. + +@item --optimize +@cindex deduplication +Optimize the store by hard-linking identical files---this is +@dfn{deduplication}. + +The daemon performs deduplication after each successful build or archive +import, unless it was started with @code{--disable-deduplication} +(@pxref{Invoking guix-daemon, @code{--disable-deduplication}}). Thus, +this option is primarily useful when the daemon was running with +@code{--disable-deduplication}. + +@end table @node Invoking guix pull @section Invoking @command{guix pull} diff --git a/guix/scripts/gc.scm b/guix/scripts/gc.scm index a250cdc197..6403893687 100644 --- a/guix/scripts/gc.scm +++ b/guix/scripts/gc.scm @@ -57,6 +57,11 @@ (define (show-help) (display (_ " --referrers list the referrers of PATHS")) (newline) + (display (_ " + --verify[=OPTS] verify the integrity of the store; OPTS is a + comma-separated combination of 'repair' and + 'contents'")) + (newline) (display (_ " -h, --help display this help and exit")) (display (_ " @@ -94,6 +99,17 @@ (define %options (lambda (opt name arg result) (alist-cons 'action 'optimize (alist-delete 'action result)))) + (option '("verify") #f #t + (let ((not-comma (char-set-complement (char-set #\,)))) + (lambda (opt name arg result) + (let ((options (if arg + (map string->symbol + (string-tokenize arg not-comma)) + '()))) + (alist-cons 'action 'verify + (alist-cons 'verify-options options + (alist-delete 'action + result))))))) (option '("list-dead") #f #f (lambda (opt name arg result) (alist-cons 'action 'list-dead @@ -177,6 +193,12 @@ (define (list-relatives relatives) (list-relatives referrers)) ((optimize) (optimize-store store)) + ((verify) + (let ((options (assoc-ref opts 'verify-options))) + (exit + (verify-store store + #:check-contents? (memq 'contents options) + #:repair? (memq 'repair options))))) ((list-dead) (for-each (cut simple-format #t "~a~%" <>) (dead-paths store))) -- cgit v1.2.3