From 66c51dc21558c6ac5149c5158df7e5b580029e84 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 29 Jan 2008 18:17:36 +0000 Subject: * nix-store --dump-db / --load-db to dump/load the Nix DB. * nix-store --register-validity: option to supply the content hash of each path. * Removed compatibility with Nix <= 0.7 stores. --- src/nix-store/nix-store.cc | 57 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 11 deletions(-) (limited to 'src/nix-store') diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc index f0e36463d48c..17b3c18fad9f 100644 --- a/src/nix-store/nix-store.cc +++ b/src/nix-store/nix-store.cc @@ -401,26 +401,31 @@ static void opReadLog(Strings opFlags, Strings opArgs) } -static void opRegisterValidity(Strings opFlags, Strings opArgs) +static void opDumpDB(Strings opFlags, Strings opArgs) { - bool reregister = false; // !!! maybe this should be the default - - for (Strings::iterator i = opFlags.begin(); - i != opFlags.end(); ++i) - if (*i == "--reregister") reregister = true; - else throw UsageError(format("unknown flag `%1%'") % *i); + if (!opFlags.empty()) throw UsageError("unknown flag"); + if (!opArgs.empty()) + throw UsageError("no arguments expected"); + PathSet validPaths = store->queryValidPaths(); + /* !!! this isn't streamy; makeValidityRegistration() builds a + potentially gigantic string. */ + cout << makeValidityRegistration(validPaths, true, true); +} - if (!opArgs.empty()) throw UsageError("no arguments expected"); +static void registerValidity(bool reregister, bool hashGiven, bool canonicalise) +{ ValidPathInfos infos; while (1) { - ValidPathInfo info = decodeValidPathInfo(cin); + ValidPathInfo info = decodeValidPathInfo(cin, hashGiven); if (info.path == "") break; if (!store->isValidPath(info.path) || reregister) { /* !!! races */ - canonicalisePathMetaData(info.path); - info.hash = hashPath(htSHA256, info.path); + if (canonicalise) + canonicalisePathMetaData(info.path); + if (!hashGiven) + info.hash = hashPath(htSHA256, info.path); infos.push_back(info); } } @@ -432,6 +437,32 @@ static void opRegisterValidity(Strings opFlags, Strings opArgs) } +static void opLoadDB(Strings opFlags, Strings opArgs) +{ + if (!opFlags.empty()) throw UsageError("unknown flag"); + if (!opArgs.empty()) + throw UsageError("no arguments expected"); + registerValidity(true, true, false); +} + + +static void opRegisterValidity(Strings opFlags, Strings opArgs) +{ + bool reregister = false; // !!! maybe this should be the default + bool hashGiven = false; + + for (Strings::iterator i = opFlags.begin(); + i != opFlags.end(); ++i) + if (*i == "--reregister") reregister = true; + else if (*i == "--hash-given") hashGiven = true; + else throw UsageError(format("unknown flag `%1%'") % *i); + + if (!opArgs.empty()) throw UsageError("no arguments expected"); + + registerValidity(reregister, hashGiven, true); +} + + static void opCheckValidity(Strings opFlags, Strings opArgs) { bool printInvalid = false; @@ -681,6 +712,10 @@ void run(Strings args) op = opQuery; else if (arg == "--read-log" || arg == "-l") op = opReadLog; + else if (arg == "--dump-db") + op = opDumpDB; + else if (arg == "--load-db") + op = opLoadDB; else if (arg == "--register-validity") op = opRegisterValidity; else if (arg == "--check-validity") -- cgit 1.4.1