Commit | Line | Data |
---|---|---|
a7a4e6a4 | 1 | # GNU Guix --- Functional package management for GNU |
349fd3b1 | 2 | # Copyright © 2013, 2014 Ludovic Courtès <ludo@gnu.org> |
a7a4e6a4 LC |
3 | # |
4 | # This file is part of GNU Guix. | |
5 | # | |
6 | # GNU Guix is free software; you can redistribute it and/or modify it | |
7 | # under the terms of the GNU General Public License as published by | |
8 | # the Free Software Foundation; either version 3 of the License, or (at | |
9 | # your option) any later version. | |
10 | # | |
11 | # GNU Guix is distributed in the hope that it will be useful, but | |
12 | # WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | # GNU General Public License for more details. | |
15 | # | |
16 | # You should have received a copy of the GNU General Public License | |
17 | # along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. | |
18 | ||
19 | # | |
20 | # Test the 'guix-register' command-line utility. | |
21 | # | |
22 | ||
23 | guix-register --version | |
24 | ||
25 | new_store="t-register-$$" | |
26 | closure="t-register-closure-$$" | |
27 | rm -rf "$new_store" | |
28 | ||
29 | exit_hook=":" | |
30 | trap "chmod -R +w $new_store ; rm -rf $new_store $closure ; \$exit_hook" EXIT | |
31 | ||
349fd3b1 LC |
32 | # |
33 | # Registering items in the current store---i.e., without '--prefix'. | |
34 | # | |
35 | ||
36 | new_file="$NIX_STORE_DIR/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-guix-register-$$" | |
37 | echo "Fake store file to test registration." > "$new_file" | |
38 | ||
39 | # Register the file with zero references and no deriver. | |
40 | guix-register <<EOF | |
41 | $new_file | |
42 | ||
43 | 0 | |
44 | EOF | |
45 | ||
46 | # Make sure it's valid, and delete it. | |
47 | guile -c " | |
48 | (use-modules (guix store)) | |
49 | (define s (open-connection)) | |
50 | (exit (and (valid-path? s \"$new_file\") | |
51 | (null? (references s \"$new_file\")) | |
52 | (pair? (delete-paths s (list \"$new_file\")))))" | |
53 | ||
54 | ||
55 | # | |
56 | # Registering items in a new store, with '--prefix'. | |
57 | # | |
58 | ||
a7a4e6a4 LC |
59 | mkdir -p "$new_store/$storedir" |
60 | new_store_dir="`cd "$new_store/$storedir" ; pwd`" | |
61 | new_store="`cd "$new_store" ; pwd`" | |
62 | ||
63 | to_copy="`guix build guile-bootstrap`" | |
64 | cp -r "$to_copy" "$new_store_dir" | |
65 | copied="$new_store_dir/`basename $to_copy`" | |
66 | ||
67 | # Create a file representing a closure with zero references, and with an empty | |
caf96deb LC |
68 | # "deriver" field. Note that we give the file name as it appears in the |
69 | # original store, and 'guix-register' translates it to match the prefix. | |
a7a4e6a4 | 70 | cat >> "$closure" <<EOF |
caf96deb | 71 | $to_copy |
a7a4e6a4 LC |
72 | |
73 | 0 | |
74 | EOF | |
75 | ||
76 | # Register it. | |
77 | guix-register -p "$new_store" < "$closure" | |
78 | ||
79 | # Doing it a second time shouldn't hurt. | |
caf96deb | 80 | guix-register --prefix "$new_store" "$closure" |
a7a4e6a4 LC |
81 | |
82 | # Now make sure this is recognized as valid. | |
83 | ||
84 | NIX_IGNORE_SYMLINK_STORE=1 | |
85 | NIX_STORE_DIR="$new_store_dir" | |
caf96deb | 86 | NIX_STATE_DIR="$new_store$localstatedir" |
aa2480e5 LC |
87 | NIX_LOG_DIR="$new_store$localstatedir/log/guix" |
88 | NIX_DB_DIR="$new_store$localstatedir/guix/db" | |
a7a4e6a4 | 89 | |
caf96deb | 90 | export NIX_IGNORE_SYMLINK_STORE NIX_STORE_DIR NIX_STATE_DIR \ |
a7a4e6a4 LC |
91 | NIX_LOG_DIR NIX_DB_DIR |
92 | ||
93 | guix-daemon --disable-chroot & | |
94 | subdaemon_pid=$! | |
95 | exit_hook="kill $subdaemon_pid" | |
96 | ||
caf96deb LC |
97 | final_name="$storedir/`basename $to_copy`" |
98 | ||
a7a4e6a4 | 99 | # At this point the copy in $new_store must be valid, and unreferenced. |
caf96deb LC |
100 | # The database under $new_store uses the $final_name, but we can't use |
101 | # that name in a 'valid-path?' query because 'assertStorePath' would kill | |
102 | # us because of the wrong prefix. So we just list dead paths instead. | |
a7a4e6a4 LC |
103 | guile -c " |
104 | (use-modules (guix store)) | |
105 | (define s (open-connection)) | |
caf96deb LC |
106 | (exit (equal? (list \"$copied\") (dead-paths s)))" |
107 | ||
108 | # When 'sqlite3' is available, check the name in the database. | |
109 | if type -P sqlite3 | |
110 | then | |
111 | echo "select * from ValidPaths where path=\"$final_name\";" | \ | |
112 | sqlite3 $NIX_DB_DIR/db.sqlite | |
113 | fi |