about summary refs log tree commit diff
path: root/src/store.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2003-08-01T15·41+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2003-08-01T15·41+0000
commitc95b4ad2906ce4076f04e0969b7080c0589a8cea (patch)
treece3d6690834645117d2d6dfa714161fe97e09ca6 /src/store.cc
parentd99d04e6442dcc39a24cebac01af117ce00a5006 (diff)
* In normaliseFState(), wrap registration of the output paths and the
  normal form in a single transaction to ensure that if we crash,
  either everything is registered or nothing is.  This is for
  recoverability: unregistered paths in the store can be deleted
  arbitrarily, while registered paths can only be deleted by running
  the garbage collector.

Diffstat (limited to 'src/store.cc')
-rw-r--r--src/store.cc15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/store.cc b/src/store.cc
index 9f8e76998285..2411a737fab7 100644
--- a/src/store.cc
+++ b/src/store.cc
@@ -105,17 +105,16 @@ void registerSubstitute(const FSId & srcId, const FSId & subId)
 }
 
 
-void registerPath(const string & _path, const FSId & id)
+void registerPath(const Transaction & txn,
+    const string & _path, const FSId & id)
 {
     string path(canonPath(_path));
-    Transaction txn(nixDB);
 
     debug(format("registering path `%1%' with id %2%")
         % path % (string) id);
 
     string oldId;
     if (nixDB.queryString(txn, dbPath2Id, path, oldId)) {
-        txn.abort();
         if (id != parseHash(oldId))
             throw Error(format("path `%1%' already contains id %2%")
                 % path % oldId);
@@ -130,8 +129,6 @@ void registerPath(const string & _path, const FSId & id)
     paths.push_back(path);
     
     nixDB.setStrings(txn, dbId2Paths, id, paths);
-
-    txn.commit();
 }
 
 
@@ -215,7 +212,9 @@ string expandId(const FSId & id, const string & target,
                 return path;
             else {
                 copyPath(path, target);
-                registerPath(target, id);
+                Transaction txn(nixDB);
+                registerPath(txn, target, id);
+                txn.commit();
                 return target;
             }
         }
@@ -267,7 +266,9 @@ void addToStore(string srcPath, string & dstPath, FSId & id,
     }
     
     copyPath(srcPath, dstPath);
-    registerPath(dstPath, id);
+    Transaction txn(nixDB);
+    registerPath(txn, dstPath, id);
+    txn.commit();
 }