diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2003-10-10T14·46+0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2003-10-10T14·46+0000 |
commit | d3d5e77810cca11cca95bbb6f0f5e15d23f31eea (patch) | |
tree | 09693dd9f6711576a587a37a20194cd82f75a45d /src/store.cc | |
parent | 1eb4da156cca1b1981ab1f60bb9797ed1e93101a (diff) |
* Reverse mappings for the successor and substitute mappings.
Diffstat (limited to 'src/store.cc')
-rw-r--r-- | src/store.cc | 52 |
1 files changed, 38 insertions, 14 deletions
diff --git a/src/store.cc b/src/store.cc index b2b479e0ddaa..de1dcca7082e 100644 --- a/src/store.cc +++ b/src/store.cc @@ -81,26 +81,50 @@ void copyPath(const Path & src, const Path & dst) } +void registerSuccessor(const Transaction & txn, + const Path & path1, const Path & path2) +{ + Path known; + if (nixDB.queryString(txn, dbSuccessors, path1, known) && + known != path2) + { + throw Error(format( + "the `impossible' happened: expression in path " + "`%1%' appears to have multiple successors " + "(known `%2%', new `%3%'") + % path1 % known % path2); + } + + Paths revs; + nixDB.queryStrings(txn, dbSuccessorsRev, path2, revs); + revs.push_back(path1); + + nixDB.setString(txn, dbSuccessors, path1, path2); + nixDB.setStrings(txn, dbSuccessorsRev, path2, revs); +} + + void registerSubstitute(const Path & srcPath, const Path & subPath) { -#if 0 - Strings subs; - queryListDB(nixDB, dbSubstitutes, srcId, subs); /* non-existence = ok */ + Transaction txn(nixDB); - for (Strings::iterator it = subs.begin(); it != subs.end(); it++) - if (parseHash(*it) == subId) return; - - subs.push_back(subId); - - setListDB(nixDB, dbSubstitutes, srcId, subs); -#endif + Paths subs; + nixDB.queryStrings(txn, dbSubstitutes, srcPath, subs); - /* For now, accept only one substitute per id. */ - Strings subs; - subs.push_back(subPath); + if (find(subs.begin(), subs.end(), subPath) != subs.end()) { + /* Nothing to do if the substitute is already known. */ + txn.abort(); + return; + } + subs.push_front(subPath); /* new substitutes take precedence */ + + Paths revs; + nixDB.queryStrings(txn, dbSubstitutesRev, subPath, revs); + revs.push_back(srcPath); - Transaction txn(nixDB); nixDB.setStrings(txn, dbSubstitutes, srcPath, subs); + nixDB.setStrings(txn, dbSubstitutesRev, subPath, revs); + txn.commit(); } |