about summary refs log tree commit diff
path: root/src/libstore
diff options
context:
space:
mode:
authorShea Levy <shea@shealevy.com>2016-07-18T22·50-0400
committerShea Levy <shea@shealevy.com>2016-11-10T16·09-0500
commit167d12b02cc8cadfaf7c28959532030d65687a8f (patch)
tree37907cb4370b395da98c592ae1b73070acd8ed2b /src/libstore
parent2af5d35fdc1171a9bdab7e2fc005673d76417c06 (diff)
build-remote: Implement in C++
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/derivations.cc3
-rw-r--r--src/libstore/pathlocks.cc2
-rw-r--r--src/libstore/ssh-store.cc2
-rw-r--r--src/libstore/store-api.cc33
-rw-r--r--src/libstore/store-api.hh2
5 files changed, 39 insertions, 3 deletions
diff --git a/src/libstore/derivations.cc b/src/libstore/derivations.cc
index d934bda382..79526c594f 100644
--- a/src/libstore/derivations.cc
+++ b/src/libstore/derivations.cc
@@ -88,9 +88,6 @@ Path writeDerivation(ref<Store> store,
 }
 
 
-MakeError(FormatError, Error)
-
-
 /* Read string `s' from stream `str'. */
 static void expect(std::istream & str, const string & s)
 {
diff --git a/src/libstore/pathlocks.cc b/src/libstore/pathlocks.cc
index 8788ee1649..8fc8620730 100644
--- a/src/libstore/pathlocks.cc
+++ b/src/libstore/pathlocks.cc
@@ -53,6 +53,8 @@ bool lockFile(int fd, LockType lockType, bool wait)
             checkInterrupt();
             if (errno != EINTR)
                 throw SysError(format("acquiring/releasing lock"));
+            else
+                return false;
         }
     } else {
         while (fcntl(fd, F_SETLK, &lock) != 0) {
diff --git a/src/libstore/ssh-store.cc b/src/libstore/ssh-store.cc
index 5166485226..3d01594009 100644
--- a/src/libstore/ssh-store.cc
+++ b/src/libstore/ssh-store.cc
@@ -49,6 +49,8 @@ SSHStore::SSHStore(string uri, const Params & params, size_t maxConnections)
     , uri(std::move(uri))
     , key(get(params, "ssh-key", ""))
 {
+    /* open a connection and perform the handshake to verify all is well */
+    connections->get();
 }
 
 string SSHStore::getUri()
diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc
index 37a2d45fef..8fdd627715 100644
--- a/src/libstore/store-api.cc
+++ b/src/libstore/store-api.cc
@@ -3,6 +3,7 @@
 #include "store-api.hh"
 #include "util.hh"
 #include "nar-info-disk-cache.hh"
+#include "thread-pool.hh"
 
 #include <future>
 
@@ -698,4 +699,36 @@ std::list<ref<Store>> getDefaultSubstituters()
 }
 
 
+void copyPaths(ref<Store> from, ref<Store> to, const Paths & storePaths)
+{
+    std::string copiedLabel = "copied";
+
+    logger->setExpected(copiedLabel, storePaths.size());
+
+    ThreadPool pool;
+
+    processGraph<Path>(pool,
+        PathSet(storePaths.begin(), storePaths.end()),
+
+        [&](const Path & storePath) {
+            return from->queryPathInfo(storePath)->references;
+        },
+
+        [&](const Path & storePath) {
+            checkInterrupt();
+
+            if (!to->isValidPath(storePath)) {
+                Activity act(*logger, lvlInfo, format("copying ‘%s’...") % storePath);
+
+                copyStorePath(from, to, storePath);
+
+                logger->incProgress(copiedLabel);
+            } else
+                logger->incExpected(copiedLabel, -1);
+        });
+
+    pool.process();
+}
+
+
 }
diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh
index f6bbc9a84e..32523dc785 100644
--- a/src/libstore/store-api.hh
+++ b/src/libstore/store-api.hh
@@ -608,6 +608,8 @@ void removeTempRoots();
 ref<Store> openStore(const std::string & uri = getEnv("NIX_REMOTE"));
 
 
+void copyPaths(ref<Store> from, ref<Store> to, const Paths & storePaths);
+
 enum StoreType {
     tDaemon,
     tLocal,