mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-14 02:06:16 +02:00
* Reverse mappings for the successor and substitute mappings.
This commit is contained in:
parent
1eb4da156c
commit
d3d5e77810
6 changed files with 68 additions and 27 deletions
|
@ -7,7 +7,9 @@ Database nixDB;
|
||||||
|
|
||||||
TableId dbValidPaths;
|
TableId dbValidPaths;
|
||||||
TableId dbSuccessors;
|
TableId dbSuccessors;
|
||||||
|
TableId dbSuccessorsRev;
|
||||||
TableId dbSubstitutes;
|
TableId dbSubstitutes;
|
||||||
|
TableId dbSubstitutesRev;
|
||||||
|
|
||||||
|
|
||||||
string nixStore = "/UNINIT";
|
string nixStore = "/UNINIT";
|
||||||
|
@ -24,7 +26,9 @@ void openDB()
|
||||||
nixDB.open(nixDBPath);
|
nixDB.open(nixDBPath);
|
||||||
dbValidPaths = nixDB.openTable("validpaths");
|
dbValidPaths = nixDB.openTable("validpaths");
|
||||||
dbSuccessors = nixDB.openTable("successors");
|
dbSuccessors = nixDB.openTable("successors");
|
||||||
|
dbSuccessorsRev = nixDB.openTable("successors-rev");
|
||||||
dbSubstitutes = nixDB.openTable("substitutes");
|
dbSubstitutes = nixDB.openTable("substitutes");
|
||||||
|
dbSubstitutesRev = nixDB.openTable("substitutes-rev");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,13 @@ extern TableId dbValidPaths;
|
||||||
extern TableId dbSuccessors;
|
extern TableId dbSuccessors;
|
||||||
|
|
||||||
|
|
||||||
|
/* dbSuccessorsRev :: Path -> [Path]
|
||||||
|
|
||||||
|
The reverse mapping of dbSuccessors.
|
||||||
|
*/
|
||||||
|
extern TableId dbSuccessorsRev;
|
||||||
|
|
||||||
|
|
||||||
/* dbSubstitutes :: Path -> [Path]
|
/* dbSubstitutes :: Path -> [Path]
|
||||||
|
|
||||||
Each pair $(p, [ps])$ tells Nix that it can realise any of the
|
Each pair $(p, [ps])$ tells Nix that it can realise any of the
|
||||||
|
@ -47,6 +54,13 @@ extern TableId dbSuccessors;
|
||||||
extern TableId dbSubstitutes;
|
extern TableId dbSubstitutes;
|
||||||
|
|
||||||
|
|
||||||
|
/* dbSubstitutesRev :: Path -> [Path]
|
||||||
|
|
||||||
|
The reverse mapping of dbSubstitutes.
|
||||||
|
*/
|
||||||
|
extern TableId dbSubstitutesRev;
|
||||||
|
|
||||||
|
|
||||||
/* Path names. */
|
/* Path names. */
|
||||||
|
|
||||||
/* nixStore is the directory where we generally store atomic and
|
/* nixStore is the directory where we generally store atomic and
|
||||||
|
|
|
@ -8,13 +8,6 @@
|
||||||
#include "globals.hh"
|
#include "globals.hh"
|
||||||
|
|
||||||
|
|
||||||
void registerSuccessor(const Transaction & txn,
|
|
||||||
const Path & path1, const Path & path2)
|
|
||||||
{
|
|
||||||
nixDB.setString(txn, dbSuccessors, path1, path2);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static Path useSuccessor(const Path & path)
|
static Path useSuccessor(const Path & path)
|
||||||
{
|
{
|
||||||
string pathSucc;
|
string pathSucc;
|
||||||
|
|
|
@ -34,9 +34,5 @@ PathSet nixExprRequisites(const Path & nePath,
|
||||||
output paths are completely contained in the set `outputs'. */
|
output paths are completely contained in the set `outputs'. */
|
||||||
PathSet findGenerators(const PathSet & outputs);
|
PathSet findGenerators(const PathSet & outputs);
|
||||||
|
|
||||||
/* Register a successor. */
|
|
||||||
void registerSuccessor(const Transaction & txn,
|
|
||||||
const Path & path1, const Path & path2);
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* !__NORMALISE_H */
|
#endif /* !__NORMALISE_H */
|
||||||
|
|
56
src/store.cc
56
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)
|
void registerSubstitute(const Path & srcPath, const Path & subPath)
|
||||||
{
|
{
|
||||||
#if 0
|
|
||||||
Strings subs;
|
|
||||||
queryListDB(nixDB, dbSubstitutes, srcId, subs); /* non-existence = ok */
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
/* For now, accept only one substitute per id. */
|
|
||||||
Strings subs;
|
|
||||||
subs.push_back(subPath);
|
|
||||||
|
|
||||||
Transaction txn(nixDB);
|
Transaction txn(nixDB);
|
||||||
|
|
||||||
|
Paths subs;
|
||||||
|
nixDB.queryStrings(txn, dbSubstitutes, srcPath, subs);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
nixDB.setStrings(txn, dbSubstitutes, srcPath, subs);
|
nixDB.setStrings(txn, dbSubstitutes, srcPath, subs);
|
||||||
|
nixDB.setStrings(txn, dbSubstitutesRev, subPath, revs);
|
||||||
|
|
||||||
txn.commit();
|
txn.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
10
src/store.hh
10
src/store.hh
|
@ -12,6 +12,16 @@ using namespace std;
|
||||||
/* Copy a path recursively. */
|
/* Copy a path recursively. */
|
||||||
void copyPath(const Path & src, const Path & dst);
|
void copyPath(const Path & src, const Path & dst);
|
||||||
|
|
||||||
|
/* Register a successor. This function accepts a transaction handle
|
||||||
|
so that it can be enclosed in an atomic operation with calls to
|
||||||
|
registerValidPath(). This must be atomic, since if we register a
|
||||||
|
successor for a derivation without registering the paths built in
|
||||||
|
the derivation, we have a successor with dangling pointers, and if
|
||||||
|
we do it in reverse order, we can get an obstructed build (since to
|
||||||
|
rebuild the successor, the outputs paths must not exist). */
|
||||||
|
void registerSuccessor(const Transaction & txn,
|
||||||
|
const Path & path1, const Path & path2);
|
||||||
|
|
||||||
/* Register a substitute. */
|
/* Register a substitute. */
|
||||||
void registerSubstitute(const Path & srcPath, const Path & subPath);
|
void registerSubstitute(const Path & srcPath, const Path & subPath);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue