diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2014-07-18 11:03:50 +0200 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2014-07-18 20:40:51 +0200 |
| commit | 689142cd759457f375230a00dc719ddc00dc2fe4 (patch) | |
| tree | d605e372177e1a2f3c895d5cfb86c401d3a1de38 | |
| parent | 1c00f83650d9412f140cce6766753a611330d6f1 (diff) | |
guix-register: Add '--state-directory' parameter.
* nix/guix-register/guix-register.cc (GUIX_OPT_STATE_DIRECTORY): New
macro.
(parse_opt): Honor it.
* tests/guix-register.sh: Add test with '--state-directory'.
* guix/store.scm (register-path): Add #:state-directory parameter.
| -rw-r--r-- | guix/store.scm | 16 | ||||
| -rw-r--r-- | nix/guix-register/guix-register.cc | 13 | ||||
| -rw-r--r-- | tests/guix-register.sh | 72 |
3 files changed, 67 insertions, 34 deletions
diff --git a/guix/store.scm b/guix/store.scm index 8c774a6db2f..79dcf22cca7 100644 --- a/guix/store.scm +++ b/guix/store.scm | |||
| @@ -797,11 +797,14 @@ signing them if SIGN? is true." | |||
| 797 | (loop tail))))))) | 797 | (loop tail))))))) |
| 798 | 798 | ||
| 799 | (define* (register-path path | 799 | (define* (register-path path |
| 800 | #:key (references '()) deriver prefix) | 800 | #:key (references '()) deriver prefix |
| 801 | state-directory) | ||
| 801 | "Register PATH as a valid store file, with REFERENCES as its list of | 802 | "Register PATH as a valid store file, with REFERENCES as its list of |
| 802 | references, and DERIVER as its deriver (.drv that led to it.) If PREFIX is | 803 | references, and DERIVER as its deriver (.drv that led to it.) If PREFIX is |
| 803 | not #f, it must be the name of the directory containing the new store to | 804 | not #f, it must be the name of the directory containing the new store to |
| 804 | initialize. Return #t on success. | 805 | initialize; if STATE-DIRECTORY is not #f, it must be a string containing the |
| 806 | absolute file name to the state directory of the store being initialized. | ||
| 807 | Return #t on success. | ||
| 805 | 808 | ||
| 806 | Use with care as it directly modifies the store! This is primarily meant to | 809 | Use with care as it directly modifies the store! This is primarily meant to |
| 807 | be used internally by the daemon's build hook." | 810 | be used internally by the daemon's build hook." |
| @@ -809,9 +812,12 @@ be used internally by the daemon's build hook." | |||
| 809 | (catch 'system-error | 812 | (catch 'system-error |
| 810 | (lambda () | 813 | (lambda () |
| 811 | (let ((pipe (apply open-pipe* OPEN_WRITE %guix-register-program | 814 | (let ((pipe (apply open-pipe* OPEN_WRITE %guix-register-program |
| 812 | (if prefix | 815 | `(,@(if prefix |
| 813 | `("--prefix" ,prefix) | 816 | `("--prefix" ,prefix) |
| 814 | '())))) | 817 | '()) |
| 818 | ,@(if state-directory | ||
| 819 | `("--state-directory" ,state-directory) | ||
| 820 | '()))))) | ||
| 815 | (and pipe | 821 | (and pipe |
| 816 | (begin | 822 | (begin |
| 817 | (format pipe "~a~%~a~%~a~%" | 823 | (format pipe "~a~%~a~%~a~%" |
diff --git a/nix/guix-register/guix-register.cc b/nix/guix-register/guix-register.cc index 4aee4fde34d..ed5ab23e411 100644 --- a/nix/guix-register/guix-register.cc +++ b/nix/guix-register/guix-register.cc | |||
| @@ -56,10 +56,14 @@ from an existing store. It updates the new store's database with \ | |||
| 56 | information about which store files are valid, and what their \ | 56 | information about which store files are valid, and what their \ |
| 57 | references are."; | 57 | references are."; |
| 58 | 58 | ||
| 59 | #define GUIX_OPT_STATE_DIRECTORY 1 | ||
| 60 | |||
| 59 | static const struct argp_option options[] = | 61 | static const struct argp_option options[] = |
| 60 | { | 62 | { |
| 61 | { "prefix", 'p', "DIRECTORY", 0, | 63 | { "prefix", 'p', "DIRECTORY", 0, |
| 62 | "Open the store that lies under DIRECTORY" }, | 64 | "Open the store that lies under DIRECTORY" }, |
| 65 | { "state-directory", GUIX_OPT_STATE_DIRECTORY, "DIRECTORY", 0, | ||
| 66 | "Use DIRECTORY as the state directory of the target store" }, | ||
| 63 | { 0, 0, 0, 0, 0 } | 67 | { 0, 0, 0, 0, 0 } |
| 64 | }; | 68 | }; |
| 65 | 69 | ||
| @@ -84,6 +88,15 @@ parse_opt (int key, char *arg, struct argp_state *state) | |||
| 84 | break; | 88 | break; |
| 85 | } | 89 | } |
| 86 | 90 | ||
| 91 | case GUIX_OPT_STATE_DIRECTORY: | ||
| 92 | { | ||
| 93 | string state_dir = canonPath (arg); | ||
| 94 | |||
| 95 | settings.nixStateDir = state_dir; | ||
| 96 | settings.nixDBPath = state_dir + "/db"; | ||
| 97 | break; | ||
| 98 | } | ||
| 99 | |||
| 87 | case ARGP_KEY_ARG: | 100 | case ARGP_KEY_ARG: |
| 88 | { | 101 | { |
| 89 | std::ifstream *file; | 102 | std::ifstream *file; |
diff --git a/tests/guix-register.sh b/tests/guix-register.sh index 28b799b5c19..e258ec1244f 100644 --- a/tests/guix-register.sh +++ b/tests/guix-register.sh | |||
| @@ -79,34 +79,48 @@ guix-register -p "$new_store" < "$closure" | |||
| 79 | # Doing it a second time shouldn't hurt. | 79 | # Doing it a second time shouldn't hurt. |
| 80 | guix-register --prefix "$new_store" "$closure" | 80 | guix-register --prefix "$new_store" "$closure" |
| 81 | 81 | ||
| 82 | # Now make sure this is recognized as valid. | 82 | # Same, but with the database stored in a different place. |
| 83 | 83 | guix-register -p "$new_store" \ | |
| 84 | NIX_STORE_DIR="$new_store_dir" | 84 | --state-directory "$new_store/chbouib" "$closure" |
| 85 | NIX_STATE_DIR="$new_store$localstatedir" | ||
| 86 | NIX_LOG_DIR="$new_store$localstatedir/log/guix" | ||
| 87 | NIX_DB_DIR="$new_store$localstatedir/guix/db" | ||
| 88 | |||
| 89 | export NIX_IGNORE_SYMLINK_STORE NIX_STORE_DIR NIX_STATE_DIR \ | ||
| 90 | NIX_LOG_DIR NIX_DB_DIR | ||
| 91 | |||
| 92 | guix-daemon --disable-chroot & | ||
| 93 | subdaemon_pid=$! | ||
| 94 | exit_hook="kill $subdaemon_pid" | ||
| 95 | 85 | ||
| 96 | final_name="$storedir/`basename $to_copy`" | 86 | # Now make sure this is recognized as valid. |
| 97 | 87 | ||
| 98 | # At this point the copy in $new_store must be valid, and unreferenced. | 88 | ls -R "$new_store" |
| 99 | # The database under $new_store uses the $final_name, but we can't use | 89 | for state_dir in "$new_store$localstatedir/guix" "$new_store/chbouib" |
| 100 | # that name in a 'valid-path?' query because 'assertStorePath' would kill | 90 | do |
| 101 | # us because of the wrong prefix. So we just list dead paths instead. | 91 | NIX_STORE_DIR="$new_store_dir" |
| 102 | guile -c " | 92 | NIX_STATE_DIR="$new_store$state_dir" |
| 103 | (use-modules (guix store)) | 93 | NIX_LOG_DIR="$new_store$state_dir/log/guix" |
| 104 | (define s (open-connection)) | 94 | NIX_DB_DIR="$new_store$state_dir/db" |
| 105 | (exit (equal? (list \"$copied\") (dead-paths s)))" | 95 | |
| 106 | 96 | export NIX_IGNORE_SYMLINK_STORE NIX_STORE_DIR NIX_STATE_DIR \ | |
| 107 | # When 'sqlite3' is available, check the name in the database. | 97 | NIX_LOG_DIR NIX_DB_DIR |
| 108 | if type -P sqlite3 | 98 | |
| 109 | then | 99 | guix-daemon --disable-chroot & |
| 110 | echo "select * from ValidPaths where path=\"$final_name\";" | \ | 100 | subdaemon_pid=$! |
| 111 | sqlite3 $NIX_DB_DIR/db.sqlite | 101 | exit_hook="kill $subdaemon_pid" |
| 112 | fi | 102 | |
| 103 | final_name="$storedir/`basename $to_copy`" | ||
| 104 | |||
| 105 | # At this point the copy in $new_store must be valid, and unreferenced. | ||
| 106 | # The database under $NIX_DB_DIR uses the $final_name, but we can't use | ||
| 107 | # that name in a 'valid-path?' query because 'assertStorePath' would kill | ||
| 108 | # us because of the wrong prefix. So we just list dead paths instead. | ||
| 109 | guile -c " | ||
| 110 | (use-modules (guix store)) | ||
| 111 | (define s (open-connection)) | ||
| 112 | (exit (equal? (list \"$copied\") (dead-paths s)))" | ||
| 113 | |||
| 114 | # Kill the daemon so we can access the database below (otherwise we may | ||
| 115 | # get "database is locked" errors.) | ||
| 116 | kill $subdaemon_pid | ||
| 117 | exit_hook=":" | ||
| 118 | while kill -0 $subdaemon_pid ; do sleep 0.5 ; done | ||
| 119 | |||
| 120 | # When 'sqlite3' is available, check the name in the database. | ||
| 121 | if type -P sqlite3 | ||
| 122 | then | ||
| 123 | echo "select * from ValidPaths where path=\"$final_name\";" | \ | ||
| 124 | sqlite3 "$NIX_DB_DIR/db.sqlite" | ||
| 125 | fi | ||
| 126 | done | ||
