about summary refs log tree commit diff
path: root/src/nix-store/nix-store.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2011-09-06T12·06+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2011-09-06T12·06+0000
commite6cb3d0a0dcfe13e9b493afdc4e2107668ec99ff (patch)
treeabd88ce033d7932ff776ac4e41d2627d2f542d20 /src/nix-store/nix-store.cc
parent82710f96f7ea72bc0f6fcc6d736e3ad4434c1988 (diff)
* Added a command ‘nix-store --verify-paths PATHS’ to check whether
  the contents of any of the given store paths have been modified.
  E.g.

    $ nix-store --verify-path $(nix-store -qR /var/run/current-system)
    path `/nix/store/m2smyiwbxidlprfxfz4rjlvz2c3mg58y-etc' was modified! expected hash `fc87e271c5fdf179b47939b08ad13440493805584b35e3014109d04d8436e7b8', got `20f1a47281b3c0cbe299ce47ad5ca7340b20ab34246426915fce0ee9116483aa'

  All paths are checked; the exit code is 1 if any path has been
  modified, 0 otherwise.

Diffstat (limited to 'src/nix-store/nix-store.cc')
-rw-r--r--src/nix-store/nix-store.cc26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc
index 00dab5f32670..371ca54af07c 100644
--- a/src/nix-store/nix-store.cc
+++ b/src/nix-store/nix-store.cc
@@ -466,11 +466,12 @@ static void opCheckValidity(Strings opFlags, Strings opArgs)
          i != opArgs.end(); ++i)
     {
         Path path = followLinksToStorePath(*i);
-        if (!store->isValidPath(path))
+        if (!store->isValidPath(path)) {
             if (printInvalid)
                 cout << format("%1%\n") % path;
             else
                 throw Error(format("path `%1%' is not valid") % path);
+        }
     }
 }
 
@@ -648,6 +649,27 @@ static void opVerify(Strings opFlags, Strings opArgs)
 }
 
 
+/* Verify whether the contents of the given store path have not changed. */
+static void opVerifyPath(Strings opFlags, Strings opArgs)
+{
+    if (!opFlags.empty())
+        throw UsageError("no flags expected");
+
+    foreach (Strings::iterator, i, opArgs) {
+        Path path = followLinksToStorePath(*i);
+        printMsg(lvlTalkative, format("checking path `%1%'...") % path);
+        ValidPathInfo info = store->queryPathInfo(path);
+        HashResult current = hashPath(info.hash.type, path);
+        if (current.first != info.hash) {
+            printMsg(lvlError,
+                format("path `%1%' was modified! expected hash `%2%', got `%3%'")
+                % path % printHash(info.hash) % printHash(current.first));
+            exitCode = 1;
+        }
+    }
+}
+
+
 static void showOptimiseStats(OptimiseStats & stats)
 {
     printMsg(lvlError,
@@ -750,6 +772,8 @@ void run(Strings args)
             op = opInit;
         else if (arg == "--verify")
             op = opVerify;
+        else if (arg == "--verify-path")
+            op = opVerifyPath;
         else if (arg == "--optimise")
             op = opOptimise;
         else if (arg == "--query-failed-paths")