1 # GNU Guix --- Functional package management for GNU
2 # Copyright © 2013, 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
4 # This file is part of GNU Guix.
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.
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.
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/>.
20 # Test the 'guix-register' command-line utility.
23 guix-register
--version
25 new_store
="t-register-$$"
26 closure
="t-register-closure-$$"
30 trap "chmod -R +w $new_store ; rm -rf $new_store $closure ; \$exit_hook" EXIT
33 # Registering items in the current store---i.e., without '--prefix'.
36 new_file
="$NIX_STORE_DIR/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-guix-register-$$"
37 echo "Fake store file to test registration." > "$new_file"
39 # Register the file with zero references and no deriver.
46 # Register an idendical file, and make sure it gets deduplicated.
47 new_file2
="$new_file-duplicate"
48 cat "$new_file" > "$new_file2"
56 (exit (= (stat:ino (stat \"$new_file\"))
57 (stat:ino (stat \"$new_file2\"))))"
59 # Make sure both are valid.
61 (use-modules (guix store))
62 (define s (open-connection))
63 (exit (and (valid-path? s \"$new_file\")
64 (valid-path? s \"$new_file2\")
65 (null? (references s \"$new_file\"))
66 (null? (references s \"$new_file2\"))))"
70 # Registering items in a new store, with '--prefix'.
73 mkdir
-p "$new_store/$storedir"
74 new_store_dir
="`cd "$new_store/$storedir" ; pwd -P`"
75 new_store
="`cd "$new_store" ; pwd -P`"
77 to_copy
="`guix build guile-bootstrap`"
78 cp -r "$to_copy" "$new_store_dir"
79 copied
="$new_store_dir/`basename $to_copy`"
81 # Create a file representing a closure with zero references, and with an empty
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.
84 cat >> "$closure" <<EOF
91 guix-register
-p "$new_store" < "$closure"
93 # Doing it a second time shouldn't hurt.
94 guix-register
--prefix "$new_store" "$closure"
96 # Same, but with the database stored in a different place.
97 guix-register
-p "$new_store" \
98 --state-directory "$new_store/chbouib" "$closure"
100 # Register duplicate files.
101 cp "$new_file" "$new_file2" "$new_store_dir"
102 guix-register
-p "$new_store" <<EOF
107 guix-register
-p "$new_store" <<EOF
113 copied_duplicate1
="$new_store_dir/`basename $new_file`"
114 copied_duplicate2
="$new_store_dir/`basename $new_file2`"
116 # Make sure there is indeed deduplication under $new_store and that there are
117 # no cross-store hard links.
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\"))))))"
125 guix gc
-d "$new_file" "$new_file2"
127 # Now make sure this is recognized as valid.
130 for state_dir
in "$localstatedir/guix" "/chbouib"
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"
136 GUIX_DAEMON_SOCKET
="$NIX_STATE_DIR/daemon-socket/socket"
138 export NIX_IGNORE_SYMLINK_STORE NIX_STORE_DIR NIX_STATE_DIR \
139 NIX_LOG_DIR NIX_DB_DIR GUIX_DAEMON_SOCKET
141 # Check whether we overflow the limitation on local socket name lengths.
142 if [ `echo "$GUIX_DAEMON_SOCKET" | wc -c` -ge 108 ]
144 # Mark the test as skipped even though we already did some work so
145 # that the remainder is not silently skipped.
149 guix-daemon
--disable-chroot &
151 exit_hook
="kill $subdaemon_pid"
153 final_name
="$storedir/`basename $to_copy`"
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.
160 (use-modules (guix store) (srfi srfi-1) (srfi srfi-34))
164 (guard (c ((nix-connection-error? c)
168 (display \"waiting for daemon socket...\")
172 (open-connection \"$GUIX_DAEMON_SOCKET\"))))
174 (exit (lset= string=?
175 (pk 1 (list \"$copied\" \"$copied_duplicate1\"
176 \"$copied_duplicate2\"))
177 (pk 2 (dead-paths s))))"
179 # Kill the daemon so we can access the database below (otherwise we may
180 # get "database is locked" errors.)
183 while kill -0 $subdaemon_pid ; do sleep 0.5 ; done
185 # When 'sqlite3' is available, check the name in the database.
188 echo "select * from ValidPaths where path=\"$final_name\";" | \
189 sqlite3
"$NIX_DB_DIR/db.sqlite"