about summary refs log tree commit diff
path: root/src/libstore
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2005-03-25T14·21+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2005-03-25T14·21+0000
commit7eaf0387639b3108f2351c513801b0d4e0b18be4 (patch)
tree58e98486baddd460a00ed1b2b2205418f0a21aa0 /src/libstore
parentc6178f0b038097584cbbac970ebdb3772de27763 (diff)
* `nix-store --verify': repair bad referer mappings.
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/store.cc22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/libstore/store.cc b/src/libstore/store.cc
index 5742bbb73870..87425430a3eb 100644
--- a/src/libstore/store.cc
+++ b/src/libstore/store.cc
@@ -774,7 +774,7 @@ void verifyStore(bool checkContents)
         if (usablePaths.find(*i) == usablePaths.end()) {
             printMsg(lvlError, format("found references entry for unusable path `%1%'")
                 % *i);
-            nixDB.delPair(txn, dbReferences, *i);
+            setReferences(txn, *i, PathSet());
         }
         else {
             bool isValid = validPaths.find(*i) != validPaths.end();
@@ -808,18 +808,28 @@ void verifyStore(bool checkContents)
             nixDB.delPair(txn, dbReferers, *i);
         }
         else {
-            PathSet referers;
+            PathSet referers, newReferers;
             queryReferers(txn, *i, referers);
             for (PathSet::iterator j = referers.begin();
                  j != referers.end(); ++j)
             {
                 Paths references;
-                nixDB.queryStrings(txn, dbReferences, *j, references);
-                if (find(references.begin(), references.end(), *i) == references.end()) {
-                    printMsg(lvlError, format("missing reference mapping from `%1%' to `%2%'")
-                        % *j % *i);
+                if (usablePaths.find(*j) == usablePaths.end()) {
+                    printMsg(lvlError, format("referer mapping from `%1%' to unusable `%2%'")
+                        % *i % *j);
+                } else {
+                    nixDB.queryStrings(txn, dbReferences, *j, references);
+                    if (find(references.begin(), references.end(), *i) == references.end()) {
+                        printMsg(lvlError, format("missing reference mapping from `%1%' to `%2%'")
+                            % *j % *i);
+                        /* !!! repair by inserting *i into references */
+                    }
+                    else newReferers.insert(*j);
                 }
             }
+            if (referers != newReferers)
+                nixDB.setStrings(txn, dbReferers, *i,
+                    Paths(newReferers.begin(), newReferers.end()));
         }
     }