about summary refs log tree commit diff
path: root/src/libstore/store.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2004-12-20T14·16+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2004-12-20T14·16+0000
commit8b9697e57596aaf142799ae6bec8bb53155dba78 (patch)
tree35495429a8b7d9598c55d5a793fef50e047e485f /src/libstore/store.cc
parentfa9259f5f519386b4f32ac9490bc73459773e589 (diff)
* An operation `nix-store --clear-substitutes' to remove all
  registered substitute mappings.

Diffstat (limited to 'src/libstore/store.cc')
-rw-r--r--src/libstore/store.cc43
1 files changed, 35 insertions, 8 deletions
diff --git a/src/libstore/store.cc b/src/libstore/store.cc
index 0c2552586c..f545d52eec 100644
--- a/src/libstore/store.cc
+++ b/src/libstore/store.cc
@@ -355,9 +355,41 @@ Substitutes querySubstitutes(const Path & srcPath)
 }
 
 
+static void unregisterPredecessors(const Path & path, Transaction & txn)
+{
+    /* Remove any successor mappings to this path (but not *from*
+       it). */
+    Paths revs;
+    nixDB.queryStrings(txn, dbSuccessorsRev, path, revs);
+    for (Paths::iterator i = revs.begin(); i != revs.end(); ++i)
+        nixDB.delPair(txn, dbSuccessors, *i);
+    nixDB.delPair(txn, dbSuccessorsRev, path);
+}
+ 
+
 void clearSubstitutes()
 {
+    Transaction txn(nixDB);
     
+    /* Iterate over all paths for which there are substitutes. */
+    Paths subKeys;
+    nixDB.enumTable(txn, dbSubstitutes, subKeys);
+    for (Paths::iterator i = subKeys.begin(); i != subKeys.end(); ++i) {
+
+        /* If this path has not become valid in the mean-while, delete
+           any successor mappings *to* it.  This is to preserve the
+           invariant the all successors are `usable' as opposed to
+           `valid' (i.e., the successor must be valid *or* have at
+           least one substitute). */
+        if (!isValidPath(*i)) {
+            unregisterPredecessors(*i, txn);
+        }
+        
+        /* Delete all substitutes for path *i. */
+        nixDB.delPair(txn, dbSubstitutes, *i);
+    }
+
+    txn.commit();
 }
 
 
@@ -375,14 +407,7 @@ static void invalidatePath(const Path & path, Transaction & txn)
     debug(format("unregistering path `%1%'") % path);
 
     nixDB.delPair(txn, dbValidPaths, path);
-
-    /* Remove any successor mappings to this path (but not *from*
-       it). */
-    Paths revs;
-    nixDB.queryStrings(txn, dbSuccessorsRev, path, revs);
-    for (Paths::iterator i = revs.begin(); i != revs.end(); ++i)
-        nixDB.delPair(txn, dbSuccessors, *i);
-    nixDB.delPair(txn, dbSuccessorsRev, path);
+    unregisterPredecessors(path, txn);
 }
 
 
@@ -511,6 +536,8 @@ void verifyStore()
         Substitutes subs = readSubstitutes(txn, *i);
 	if (subs.size() > 0)
 	    usablePaths.insert(*i);
+        else
+            nixDB.delPair(txn, dbSubstitutes, *i);
     }
 
     /* Check that the values of the successor mappings are usable