build-remote: Implement in C++

This commit is contained in:
Shea Levy 2016-07-18 18:50:27 -04:00
parent 2af5d35fdc
commit 167d12b02c
12 changed files with 338 additions and 30 deletions

View file

@ -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)
{

View file

@ -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) {

View file

@ -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()

View file

@ -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();
}
}

View file

@ -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,