Commit | Line | Data |
---|---|---|
a7a4e6a4 | 1 | # GNU Guix --- Functional package management for GNU |
bd98ad1f | 2 | # Copyright © 2013, 2014, 2015 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 | ||
c6df0994 LC |
46 | # Register an idendical file, and make sure it gets deduplicated. |
47 | new_file2="$new_file-duplicate" | |
48 | cat "$new_file" > "$new_file2" | |
49 | guix-register <<EOF | |
50 | $new_file2 | |
51 | ||
52 | 0 | |
53 | EOF | |
54 | ||
55 | guile -c " | |
56 | (exit (= (stat:ino (stat \"$new_file\")) | |
57 | (stat:ino (stat \"$new_file2\"))))" | |
58 | ||
36975584 | 59 | # Make sure both are valid. |
349fd3b1 LC |
60 | guile -c " |
61 | (use-modules (guix store)) | |
62 | (define s (open-connection)) | |
63 | (exit (and (valid-path? s \"$new_file\") | |
c6df0994 | 64 | (valid-path? s \"$new_file2\") |
349fd3b1 | 65 | (null? (references s \"$new_file\")) |
36975584 | 66 | (null? (references s \"$new_file2\"))))" |
349fd3b1 LC |
67 | |
68 | ||
69 | # | |
70 | # Registering items in a new store, with '--prefix'. | |
71 | # | |
72 | ||
a7a4e6a4 | 73 | mkdir -p "$new_store/$storedir" |
8ad49499 LC |
74 | new_store_dir="`cd "$new_store/$storedir" ; pwd -P`" |
75 | new_store="`cd "$new_store" ; pwd -P`" | |
a7a4e6a4 LC |
76 | |
77 | to_copy="`guix build guile-bootstrap`" | |
78 | cp -r "$to_copy" "$new_store_dir" | |
79 | copied="$new_store_dir/`basename $to_copy`" | |
80 | ||
81 | # Create a file representing a closure with zero references, and with an empty | |
caf96deb LC |
82 | # "deriver" field. Note that we give the file name as it appears in the |
83 | # original store, and 'guix-register' translates it to match the prefix. | |
a7a4e6a4 | 84 | cat >> "$closure" <<EOF |
caf96deb | 85 | $to_copy |
a7a4e6a4 LC |
86 | |
87 | 0 | |
88 | EOF | |
89 | ||
90 | # Register it. | |
91 | guix-register -p "$new_store" < "$closure" | |
92 | ||
93 | # Doing it a second time shouldn't hurt. | |
caf96deb | 94 | guix-register --prefix "$new_store" "$closure" |
a7a4e6a4 | 95 | |
689142cd LC |
96 | # Same, but with the database stored in a different place. |
97 | guix-register -p "$new_store" \ | |
98 | --state-directory "$new_store/chbouib" "$closure" | |
a7a4e6a4 | 99 | |
36975584 LC |
100 | # Register duplicate files. |
101 | cp "$new_file" "$new_file2" "$new_store_dir" | |
102 | guix-register -p "$new_store" <<EOF | |
103 | $new_file | |
104 | ||
105 | 0 | |
106 | EOF | |
107 | guix-register -p "$new_store" <<EOF | |
108 | $new_file2 | |
109 | ||
110 | 0 | |
111 | EOF | |
112 | ||
113 | copied_duplicate1="$new_store_dir/`basename $new_file`" | |
114 | copied_duplicate2="$new_store_dir/`basename $new_file2`" | |
115 | ||
116 | # Make sure there is indeed deduplication under $new_store and that there are | |
117 | # no cross-store hard links. | |
118 | guile -c " | |
119 | (exit (and (= (stat:ino (stat \"$copied_duplicate1\")) | |
120 | (stat:ino (stat \"$copied_duplicate2\"))) | |
121 | (not (= (stat:ino (stat \"$new_file\")) | |
122 | (stat:ino (stat \"$copied_duplicate1\"))))))" | |
123 | ||
124 | # Delete them. | |
125 | guix gc -d "$new_file" "$new_file2" | |
126 | ||
689142cd | 127 | # Now make sure this is recognized as valid. |
caf96deb | 128 | |
689142cd | 129 | ls -R "$new_store" |
58f485cc | 130 | for state_dir in "$localstatedir/guix" "/chbouib" |
689142cd LC |
131 | do |
132 | NIX_STORE_DIR="$new_store_dir" | |
133 | NIX_STATE_DIR="$new_store$state_dir" | |
134 | NIX_LOG_DIR="$new_store$state_dir/log/guix" | |
135 | NIX_DB_DIR="$new_store$state_dir/db" | |
4ae1fe14 | 136 | GUIX_DAEMON_SOCKET="$NIX_STATE_DIR/daemon-socket/socket" |
689142cd LC |
137 | |
138 | export NIX_IGNORE_SYMLINK_STORE NIX_STORE_DIR NIX_STATE_DIR \ | |
4ae1fe14 | 139 | NIX_LOG_DIR NIX_DB_DIR GUIX_DAEMON_SOCKET |
689142cd | 140 | |
bd98ad1f | 141 | # Check whether we overflow the limitation on local socket name lengths. |
4ae1fe14 | 142 | if [ `echo "$GUIX_DAEMON_SOCKET" | wc -c` -ge 108 ] |
bd98ad1f LC |
143 | then |
144 | # Mark the test as skipped even though we already did some work so | |
145 | # that the remainder is not silently skipped. | |
146 | exit 77 | |
147 | fi | |
148 | ||
689142cd LC |
149 | guix-daemon --disable-chroot & |
150 | subdaemon_pid=$! | |
151 | exit_hook="kill $subdaemon_pid" | |
152 | ||
153 | final_name="$storedir/`basename $to_copy`" | |
154 | ||
155 | # At this point the copy in $new_store must be valid, and unreferenced. | |
156 | # The database under $NIX_DB_DIR uses the $final_name, but we can't use | |
157 | # that name in a 'valid-path?' query because 'assertStorePath' would kill | |
158 | # us because of the wrong prefix. So we just list dead paths instead. | |
159 | guile -c " | |
36975584 | 160 | (use-modules (guix store) (srfi srfi-1)) |
4ae1fe14 | 161 | (define s (open-connection \"$GUIX_DAEMON_SOCKET\")) |
36975584 LC |
162 | (exit (lset= string=? |
163 | (pk 1 (list \"$copied\" \"$copied_duplicate1\" | |
164 | \"$copied_duplicate2\")) | |
165 | (pk 2 (dead-paths s))))" | |
689142cd LC |
166 | |
167 | # Kill the daemon so we can access the database below (otherwise we may | |
168 | # get "database is locked" errors.) | |
169 | kill $subdaemon_pid | |
170 | exit_hook=":" | |
171 | while kill -0 $subdaemon_pid ; do sleep 0.5 ; done | |
172 | ||
173 | # When 'sqlite3' is available, check the name in the database. | |
174 | if type -P sqlite3 | |
175 | then | |
176 | echo "select * from ValidPaths where path=\"$final_name\";" | \ | |
177 | sqlite3 "$NIX_DB_DIR/db.sqlite" | |
178 | fi | |
179 | done |