From c95b4ad2906ce4076f04e0969b7080c0589a8cea Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 1 Aug 2003 15:41:47 +0000 Subject: * 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. --- src/store.cc | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/store.cc') 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(); } -- cgit 1.4.1