about summary refs log tree commit diff
path: root/src/nix-store/nix-store.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/nix-store/nix-store.cc')
-rw-r--r--src/nix-store/nix-store.cc57
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")