mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-10 16:26:18 +02:00
* A function to query just the database id of a valid path.
This commit is contained in:
parent
6baa2a2f5e
commit
cfe742cfc5
2 changed files with 22 additions and 16 deletions
|
@ -461,10 +461,8 @@ void LocalStore::registerValidPath(const ValidPathInfo & info)
|
||||||
|
|
||||||
unsigned long long id = addValidPath(info2);
|
unsigned long long id = addValidPath(info2);
|
||||||
|
|
||||||
foreach (PathSet::const_iterator, i, info2.references) {
|
foreach (PathSet::const_iterator, i, info2.references)
|
||||||
ValidPathInfo ref = queryPathInfo(*i);
|
addReference(id, queryValidPathId(*i));
|
||||||
addReference(id, ref.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
txn.commit();
|
txn.commit();
|
||||||
}
|
}
|
||||||
|
@ -551,6 +549,17 @@ ValidPathInfo LocalStore::queryPathInfo(const Path & path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
unsigned long long LocalStore::queryValidPathId(const Path & path)
|
||||||
|
{
|
||||||
|
SQLiteStmtUse use(stmtQueryPathInfo);
|
||||||
|
stmtQueryPathInfo.bind(path);
|
||||||
|
int res = sqlite3_step(stmtQueryPathInfo);
|
||||||
|
if (res == SQLITE_ROW) return sqlite3_column_int(stmtQueryPathInfo, 0);
|
||||||
|
if (res == SQLITE_DONE) throw Error(format("path `%1%' is not valid") % path);
|
||||||
|
throw SQLiteError(db, "querying path in database");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool LocalStore::isValidPath(const Path & path)
|
bool LocalStore::isValidPath(const Path & path)
|
||||||
{
|
{
|
||||||
SQLiteStmtUse use(stmtQueryPathInfo);
|
SQLiteStmtUse use(stmtQueryPathInfo);
|
||||||
|
@ -644,7 +653,7 @@ PathSet LocalStore::queryDerivationOutputs(const Path & path)
|
||||||
SQLiteTxn txn(db);
|
SQLiteTxn txn(db);
|
||||||
|
|
||||||
SQLiteStmtUse use(stmtQueryDerivationOutputs);
|
SQLiteStmtUse use(stmtQueryDerivationOutputs);
|
||||||
stmtQueryDerivationOutputs.bind(queryPathInfo(path).id);
|
stmtQueryDerivationOutputs.bind(queryValidPathId(path));
|
||||||
|
|
||||||
PathSet outputs;
|
PathSet outputs;
|
||||||
int r;
|
int r;
|
||||||
|
@ -778,9 +787,9 @@ void LocalStore::registerValidPaths(const ValidPathInfos & infos)
|
||||||
foreach (ValidPathInfos::const_iterator, i, infos) addValidPath(*i);
|
foreach (ValidPathInfos::const_iterator, i, infos) addValidPath(*i);
|
||||||
|
|
||||||
foreach (ValidPathInfos::const_iterator, i, infos) {
|
foreach (ValidPathInfos::const_iterator, i, infos) {
|
||||||
unsigned long long referrer = queryPathInfo(i->path).id;
|
unsigned long long referrer = queryValidPathId(i->path);
|
||||||
foreach (PathSet::iterator, j, i->references)
|
foreach (PathSet::iterator, j, i->references)
|
||||||
addReference(referrer, queryPathInfo(*j).id);
|
addReference(referrer, queryValidPathId(*j));
|
||||||
}
|
}
|
||||||
|
|
||||||
txn.commit();
|
txn.commit();
|
||||||
|
@ -1229,11 +1238,8 @@ void LocalStore::upgradeStore6()
|
||||||
|
|
||||||
SQLiteTxn txn(db);
|
SQLiteTxn txn(db);
|
||||||
|
|
||||||
std::map<Path, sqlite3_int64> pathToId;
|
|
||||||
|
|
||||||
foreach (PathSet::iterator, i, validPaths) {
|
foreach (PathSet::iterator, i, validPaths) {
|
||||||
ValidPathInfo info = queryPathInfoOld(*i);
|
addValidPath(queryPathInfoOld(*i));
|
||||||
pathToId[*i] = addValidPath(info);
|
|
||||||
std::cerr << ".";
|
std::cerr << ".";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1241,11 +1247,9 @@ void LocalStore::upgradeStore6()
|
||||||
|
|
||||||
foreach (PathSet::iterator, i, validPaths) {
|
foreach (PathSet::iterator, i, validPaths) {
|
||||||
ValidPathInfo info = queryPathInfoOld(*i);
|
ValidPathInfo info = queryPathInfoOld(*i);
|
||||||
foreach (PathSet::iterator, j, info.references) {
|
unsigned long long referrer = queryValidPathId(*i);
|
||||||
if (pathToId.find(*j) == pathToId.end())
|
foreach (PathSet::iterator, j, info.references)
|
||||||
throw Error(format("path `%1%' referenced by `%2%' is invalid") % *j % *i);
|
addReference(referrer, queryValidPathId(*j));
|
||||||
addReference(pathToId[*i], pathToId[*j]);
|
|
||||||
}
|
|
||||||
std::cerr << ".";
|
std::cerr << ".";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -213,6 +213,8 @@ private:
|
||||||
|
|
||||||
void prepareStatements();
|
void prepareStatements();
|
||||||
|
|
||||||
|
unsigned long long queryValidPathId(const Path & path);
|
||||||
|
|
||||||
unsigned long long addValidPath(const ValidPathInfo & info);
|
unsigned long long addValidPath(const ValidPathInfo & info);
|
||||||
|
|
||||||
void addReference(unsigned long long referrer, unsigned long long reference);
|
void addReference(unsigned long long referrer, unsigned long long reference);
|
||||||
|
|
Loading…
Reference in a new issue