about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/libstore/local-store.cc69
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. */
+        }
+    }
 }