diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2008-01-29T18·17+0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2008-01-29T18·17+0000 |
commit | 66c51dc21558c6ac5149c5158df7e5b580029e84 (patch) | |
tree | 455b9e454c24e0c9d132f8881098e5d240250928 /src/nix-store/nix-store.cc | |
parent | 5b5a3af98372029f3a870cf18cc1442f1434be85 (diff) |
* 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.
Diffstat (limited to 'src/nix-store/nix-store.cc')
-rw-r--r-- | src/nix-store/nix-store.cc | 57 |
1 files changed, 46 insertions, 11 deletions
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") |