diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2010-12-14T13·25+0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2010-12-14T13·25+0000 |
commit | 3dd02580e324d04ebfe999779978b4aa0f999ccd (patch) | |
tree | 8268fa86d493e36c54fa4f314c2ef4384d04e348 /src/libstore/local-store.cc | |
parent | d787285af997a607bb678f39f340e663fafd3122 (diff) |
* I forgot to catch SQLiteBusy in registerValidPaths(). So
registerValidPaths() now handles busy errors and registerValidPath() is simply a wrapper around it.
Diffstat (limited to 'src/libstore/local-store.cc')
-rw-r--r-- | src/libstore/local-store.cc | 69 |
1 files changed, 31 insertions, 38 deletions
diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index 32c7a533056e..56d05c7bb55c 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -463,7 +463,7 @@ unsigned long long LocalStore::addValidPath(const ValidPathInfo & info) SQLiteStmtUse use(stmtRegisterValidPath); stmtRegisterValidPath.bind(info.path); stmtRegisterValidPath.bind("sha256:" + printHash(info.hash)); - stmtRegisterValidPath.bind(info.registrationTime); + stmtRegisterValidPath.bind(info.registrationTime == 0 ? time(0) : info.registrationTime); if (info.deriver != "") stmtRegisterValidPath.bind(info.deriver); else @@ -506,31 +506,6 @@ void LocalStore::addReference(unsigned long long referrer, unsigned long long re } -void LocalStore::registerValidPath(const ValidPathInfo & info) -{ - assert(info.hash.type == htSHA256); - ValidPathInfo info2(info); - if (info2.registrationTime == 0) info2.registrationTime = time(0); - - while (1) { - try { - SQLiteTxn txn(db); - - unsigned long long id = addValidPath(info2); - - foreach (PathSet::const_iterator, i, info2.references) - addReference(id, queryValidPathId(*i)); - - txn.commit(); - break; - } catch (SQLiteBusy & e) { - /* Retry; the `txn' destructor will roll back the current - transaction. */ - } - } -} - - void LocalStore::registerFailedPath(const Path & path) { if (hasPathFailed(path)) return; @@ -896,22 +871,40 @@ Hash LocalStore::queryPathHash(const Path & path) } +void LocalStore::registerValidPath(const ValidPathInfo & info) +{ + ValidPathInfos infos; + infos.push_back(info); + registerValidPaths(infos); +} + + void LocalStore::registerValidPaths(const ValidPathInfos & infos) { - SQLiteTxn txn(db); + while (1) { + try { + SQLiteTxn txn(db); - foreach (ValidPathInfos::const_iterator, i, infos) - /* !!! Maybe the registration info should be updated if the - path is already valid. */ - if (!isValidPath(i->path)) addValidPath(*i); - - foreach (ValidPathInfos::const_iterator, i, infos) { - unsigned long long referrer = queryValidPathId(i->path); - foreach (PathSet::iterator, j, i->references) - addReference(referrer, queryValidPathId(*j)); - } + foreach (ValidPathInfos::const_iterator, i, infos) { + assert(i->hash.type == htSHA256); + /* !!! Maybe the registration info should be updated if the + path is already valid. */ + if (!isValidPath(i->path)) addValidPath(*i); + } - txn.commit(); + foreach (ValidPathInfos::const_iterator, i, infos) { + unsigned long long referrer = queryValidPathId(i->path); + foreach (PathSet::iterator, j, i->references) + addReference(referrer, queryValidPathId(*j)); + } + + txn.commit(); + break; + } catch (SQLiteBusy & e) { + /* Retry; the `txn' destructor will roll back the current + transaction. */ + } + } } |