guix-register: Expect closures to refer to the original store.

* nix/guix-register/guix-register.cc (prefix): New variable.
  (parse_opt): Use it.
  (register_validity): Change 'info.path' to the final store name.
  Hash the final under its real path.
* tests/guix-register.sh: Adjust the contents of $closure accordingly.
  Rename 'NIX_LOCALSTATE_DIR' to 'NIX_STATE_DIR'.  Don't try to call
  'valid-path?'.  Add test using 'sqlite3'.
This commit is contained in:
Ludovic Courtès 2013-09-23 21:24:18 +02:00
parent a4141d6d53
commit caf96debc2
2 changed files with 37 additions and 11 deletions

View File

@ -62,6 +62,10 @@ static const struct argp_option options[] =
{ 0, 0, 0, 0, 0 }
};
/* Prefix of the store being populated. */
static std::string prefix;
/* Parse a single option. */
static error_t
parse_opt (int key, char *arg, struct argp_state *state)
@ -70,8 +74,8 @@ parse_opt (int key, char *arg, struct argp_state *state)
{
case 'p':
{
string prefix = canonPath (arg);
settings.nixStore = prefix + NIX_STORE_DIR;
prefix = canonPath (arg);
settings.nixStore = NIX_STORE_DIR;
settings.nixDataDir = prefix + NIX_DATA_DIR;
settings.nixLogDir = prefix + NIX_LOG_DIR;
settings.nixStateDir = prefix + NIX_STATE_DIR;
@ -128,15 +132,25 @@ register_validity (LocalStore *store, std::istream &input,
ValidPathInfo info = decodeValidPathInfo (input, hashGiven);
if (info.path == "")
break;
/* Rewrite the input to refer final name, as if we were in a chroot
under PREFIX. */
std::string final_prefix (NIX_STORE_DIR "/");
info.path = final_prefix + baseNameOf (info.path);
/* Keep its real path to canonicalize it and compute its hash. */
std::string real_path;
real_path = prefix + "/" + settings.nixStore + "/" + baseNameOf (info.path);
if (!store->isValidPath (info.path) || reregister)
{
/* !!! races */
if (canonicalise)
canonicalisePathMetaData (info.path, -1);
canonicalisePathMetaData (real_path, -1);
if (!hashGiven)
{
HashResult hash = hashPath (htSHA256, info.path);
HashResult hash = hashPath (htSHA256, real_path);
info.hash = hash.first;
info.narSize = hash.second;
}

View File

@ -38,9 +38,10 @@ cp -r "$to_copy" "$new_store_dir"
copied="$new_store_dir/`basename $to_copy`"
# Create a file representing a closure with zero references, and with an empty
# "deriver" field.
# "deriver" field. Note that we give the file name as it appears in the
# original store, and 'guix-register' translates it to match the prefix.
cat >> "$closure" <<EOF
$copied
$to_copy
0
EOF
@ -49,26 +50,37 @@ EOF
guix-register -p "$new_store" < "$closure"
# Doing it a second time shouldn't hurt.
guix-register -p "$new_store" "$closure"
guix-register --prefix "$new_store" "$closure"
# Now make sure this is recognized as valid.
NIX_IGNORE_SYMLINK_STORE=1
NIX_STORE_DIR="$new_store_dir"
NIX_LOCALSTATE_DIR="$new_store$localstatedir"
NIX_STATE_DIR="$new_store$localstatedir"
NIX_LOG_DIR="$new_store$localstatedir/log/nix"
NIX_DB_DIR="$new_store$localstatedir/nix/db"
export NIX_IGNORE_SYMLINK_STORE NIX_STORE_DIR NIX_LOCALSTATE_DIR \
export NIX_IGNORE_SYMLINK_STORE NIX_STORE_DIR NIX_STATE_DIR \
NIX_LOG_DIR NIX_DB_DIR
guix-daemon --disable-chroot &
subdaemon_pid=$!
exit_hook="kill $subdaemon_pid"
final_name="$storedir/`basename $to_copy`"
# At this point the copy in $new_store must be valid, and unreferenced.
# The database under $new_store uses the $final_name, but we can't use
# that name in a 'valid-path?' query because 'assertStorePath' would kill
# us because of the wrong prefix. So we just list dead paths instead.
guile -c "
(use-modules (guix store))
(define s (open-connection))
(exit (and (valid-path? s \"$copied\")
(equal? (list \"$copied\") (dead-paths s))))"
(exit (equal? (list \"$copied\") (dead-paths s)))"
# When 'sqlite3' is available, check the name in the database.
if type -P sqlite3
then
echo "select * from ValidPaths where path=\"$final_name\";" | \
sqlite3 $NIX_DB_DIR/db.sqlite
fi