mirror of
https://github.com/NixOS/nix.git
synced 2025-11-16 15:32:43 +01:00
Apply clang-format universally.
* It is tough to contribute to a project that doesn't use a formatter, * It is extra hard to contribute to a project which has configured the formatter, but ignores it for some files * Code formatting makes it harder to hide obscure / weird bugs by accident or on purpose, Let's rip the bandaid off? Note that PRs currently in flight should be able to be merged relatively easily by applying `clang-format` to their tip prior to merge.
This commit is contained in:
parent
41bf87ec70
commit
e4f62e4608
587 changed files with 23258 additions and 23135 deletions
|
|
@ -27,30 +27,29 @@ namespace nix {
|
|||
RemoteStore::RemoteStore(const Config & config)
|
||||
: Store{config}
|
||||
, config{config}
|
||||
, connections(make_ref<Pool<Connection>>(
|
||||
std::max(1, config.maxConnections.get()),
|
||||
[this]() {
|
||||
auto conn = openConnectionWrapper();
|
||||
try {
|
||||
initConnection(*conn);
|
||||
} catch (...) {
|
||||
failed = true;
|
||||
throw;
|
||||
}
|
||||
return conn;
|
||||
},
|
||||
[this](const ref<Connection> & r) {
|
||||
return
|
||||
r->to.good()
|
||||
&& r->from.good()
|
||||
&& std::chrono::duration_cast<std::chrono::seconds>(
|
||||
std::chrono::steady_clock::now() - r->startTime).count() < this->config.maxConnectionAge;
|
||||
}
|
||||
))
|
||||
, connections(
|
||||
make_ref<Pool<Connection>>(
|
||||
std::max(1, config.maxConnections.get()),
|
||||
[this]() {
|
||||
auto conn = openConnectionWrapper();
|
||||
try {
|
||||
initConnection(*conn);
|
||||
} catch (...) {
|
||||
failed = true;
|
||||
throw;
|
||||
}
|
||||
return conn;
|
||||
},
|
||||
[this](const ref<Connection> & r) {
|
||||
return r->to.good() && r->from.good()
|
||||
&& std::chrono::duration_cast<std::chrono::seconds>(
|
||||
std::chrono::steady_clock::now() - r->startTime)
|
||||
.count()
|
||||
< this->config.maxConnectionAge;
|
||||
}))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ref<RemoteStore::Connection> RemoteStore::openConnectionWrapper()
|
||||
{
|
||||
if (failed)
|
||||
|
|
@ -63,7 +62,6 @@ ref<RemoteStore::Connection> RemoteStore::openConnectionWrapper()
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void RemoteStore::initConnection(Connection & conn)
|
||||
{
|
||||
/* Send the magic greeting, check for the reply. */
|
||||
|
|
@ -73,9 +71,8 @@ void RemoteStore::initConnection(Connection & conn)
|
|||
StringSink saved;
|
||||
TeeSource tee(conn.from, saved);
|
||||
try {
|
||||
auto [protoVersion, features] = WorkerProto::BasicClientConnection::handshake(
|
||||
conn.to, tee, PROTOCOL_VERSION,
|
||||
WorkerProto::allFeatures);
|
||||
auto [protoVersion, features] =
|
||||
WorkerProto::BasicClientConnection::handshake(conn.to, tee, PROTOCOL_VERSION, WorkerProto::allFeatures);
|
||||
conn.protoVersion = protoVersion;
|
||||
conn.features = features;
|
||||
} catch (SerialisationError & e) {
|
||||
|
|
@ -95,31 +92,22 @@ void RemoteStore::initConnection(Connection & conn)
|
|||
debug("negotiated feature '%s'", feature);
|
||||
|
||||
auto ex = conn.processStderrReturn();
|
||||
if (ex) std::rethrow_exception(ex);
|
||||
}
|
||||
catch (Error & e) {
|
||||
if (ex)
|
||||
std::rethrow_exception(ex);
|
||||
} catch (Error & e) {
|
||||
throw Error("cannot open connection to remote store '%s': %s", getUri(), e.what());
|
||||
}
|
||||
|
||||
setOptions(conn);
|
||||
}
|
||||
|
||||
|
||||
void RemoteStore::setOptions(Connection & conn)
|
||||
{
|
||||
conn.to << WorkerProto::Op::SetOptions
|
||||
<< settings.keepFailed
|
||||
<< settings.keepGoing
|
||||
<< settings.tryFallback
|
||||
<< verbosity
|
||||
<< settings.maxBuildJobs
|
||||
<< settings.maxSilentTime
|
||||
<< true
|
||||
<< (settings.verboseBuild ? lvlError : lvlVomit)
|
||||
<< 0 // obsolete log type
|
||||
<< 0 /* obsolete print build trace */
|
||||
<< settings.buildCores
|
||||
<< settings.useSubstitutes;
|
||||
conn.to << WorkerProto::Op::SetOptions << settings.keepFailed << settings.keepGoing << settings.tryFallback
|
||||
<< verbosity << settings.maxBuildJobs << settings.maxSilentTime << true
|
||||
<< (settings.verboseBuild ? lvlError : lvlVomit) << 0 // obsolete log type
|
||||
<< 0 /* obsolete print build trace */
|
||||
<< settings.buildCores << settings.useSubstitutes;
|
||||
|
||||
if (GET_PROTOCOL_MINOR(conn.protoVersion) >= 12) {
|
||||
std::map<std::string, nix::Config::SettingInfo> overrides;
|
||||
|
|
@ -141,10 +129,10 @@ void RemoteStore::setOptions(Connection & conn)
|
|||
}
|
||||
|
||||
auto ex = conn.processStderrReturn();
|
||||
if (ex) std::rethrow_exception(ex);
|
||||
if (ex)
|
||||
std::rethrow_exception(ex);
|
||||
}
|
||||
|
||||
|
||||
RemoteStore::ConnectionHandle::~ConnectionHandle()
|
||||
{
|
||||
if (!daemonException && std::uncaught_exceptions()) {
|
||||
|
|
@ -158,7 +146,6 @@ void RemoteStore::ConnectionHandle::processStderr(Sink * sink, Source * source,
|
|||
handle->processStderr(&daemonException, sink, source, flush, block);
|
||||
}
|
||||
|
||||
|
||||
RemoteStore::ConnectionHandle RemoteStore::getConnection()
|
||||
{
|
||||
return ConnectionHandle(connections->get());
|
||||
|
|
@ -177,21 +164,20 @@ bool RemoteStore::isValidPathUncached(const StorePath & path)
|
|||
return readInt(conn->from);
|
||||
}
|
||||
|
||||
|
||||
StorePathSet RemoteStore::queryValidPaths(const StorePathSet & paths, SubstituteFlag maybeSubstitute)
|
||||
{
|
||||
auto conn(getConnection());
|
||||
if (GET_PROTOCOL_MINOR(conn->protoVersion) < 12) {
|
||||
StorePathSet res;
|
||||
for (auto & i : paths)
|
||||
if (isValidPath(i)) res.insert(i);
|
||||
if (isValidPath(i))
|
||||
res.insert(i);
|
||||
return res;
|
||||
} else {
|
||||
return conn->queryValidPaths(*this, &conn.daemonException, paths, maybeSubstitute);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
StorePathSet RemoteStore::queryAllValidPaths()
|
||||
{
|
||||
auto conn(getConnection());
|
||||
|
|
@ -200,7 +186,6 @@ StorePathSet RemoteStore::queryAllValidPaths()
|
|||
return WorkerProto::Serialise<StorePathSet>::read(*this, *conn);
|
||||
}
|
||||
|
||||
|
||||
StorePathSet RemoteStore::querySubstitutablePaths(const StorePathSet & paths)
|
||||
{
|
||||
auto conn(getConnection());
|
||||
|
|
@ -209,7 +194,8 @@ StorePathSet RemoteStore::querySubstitutablePaths(const StorePathSet & paths)
|
|||
for (auto & i : paths) {
|
||||
conn->to << WorkerProto::Op::HasSubstitutes << printStorePath(i);
|
||||
conn.processStderr();
|
||||
if (readInt(conn->from)) res.insert(i);
|
||||
if (readInt(conn->from))
|
||||
res.insert(i);
|
||||
}
|
||||
return res;
|
||||
} else {
|
||||
|
|
@ -220,10 +206,10 @@ StorePathSet RemoteStore::querySubstitutablePaths(const StorePathSet & paths)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void RemoteStore::querySubstitutablePathInfos(const StorePathCAMap & pathsMap, SubstitutablePathInfos & infos)
|
||||
{
|
||||
if (pathsMap.empty()) return;
|
||||
if (pathsMap.empty())
|
||||
return;
|
||||
|
||||
auto conn(getConnection());
|
||||
|
||||
|
|
@ -234,7 +220,8 @@ void RemoteStore::querySubstitutablePathInfos(const StorePathCAMap & pathsMap, S
|
|||
conn->to << WorkerProto::Op::QuerySubstitutablePathInfo << printStorePath(i.first);
|
||||
conn.processStderr();
|
||||
unsigned int reply = readInt(conn->from);
|
||||
if (reply == 0) continue;
|
||||
if (reply == 0)
|
||||
continue;
|
||||
auto deriver = readString(conn->from);
|
||||
if (deriver != "")
|
||||
info.deriver = parseStorePath(deriver);
|
||||
|
|
@ -265,30 +252,26 @@ void RemoteStore::querySubstitutablePathInfos(const StorePathCAMap & pathsMap, S
|
|||
info.downloadSize = readLongLong(conn->from);
|
||||
info.narSize = readLongLong(conn->from);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void RemoteStore::queryPathInfoUncached(const StorePath & path,
|
||||
Callback<std::shared_ptr<const ValidPathInfo>> callback) noexcept
|
||||
void RemoteStore::queryPathInfoUncached(
|
||||
const StorePath & path, Callback<std::shared_ptr<const ValidPathInfo>> callback) noexcept
|
||||
{
|
||||
try {
|
||||
std::shared_ptr<const ValidPathInfo> info;
|
||||
{
|
||||
auto conn(getConnection());
|
||||
info = std::make_shared<ValidPathInfo>(
|
||||
StorePath{path},
|
||||
conn->queryPathInfo(*this, &conn.daemonException, path));
|
||||
|
||||
StorePath{path}, conn->queryPathInfo(*this, &conn.daemonException, path));
|
||||
}
|
||||
callback(std::move(info));
|
||||
} catch (...) { callback.rethrow(); }
|
||||
} catch (...) {
|
||||
callback.rethrow();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void RemoteStore::queryReferrers(const StorePath & path,
|
||||
StorePathSet & referrers)
|
||||
void RemoteStore::queryReferrers(const StorePath & path, StorePathSet & referrers)
|
||||
{
|
||||
auto conn(getConnection());
|
||||
conn->to << WorkerProto::Op::QueryReferrers << printStorePath(path);
|
||||
|
|
@ -297,7 +280,6 @@ void RemoteStore::queryReferrers(const StorePath & path,
|
|||
referrers.insert(i);
|
||||
}
|
||||
|
||||
|
||||
StorePathSet RemoteStore::queryValidDerivers(const StorePath & path)
|
||||
{
|
||||
auto conn(getConnection());
|
||||
|
|
@ -306,7 +288,6 @@ StorePathSet RemoteStore::queryValidDerivers(const StorePath & path)
|
|||
return WorkerProto::Serialise<StorePathSet>::read(*this, *conn);
|
||||
}
|
||||
|
||||
|
||||
StorePathSet RemoteStore::queryDerivationOutputs(const StorePath & path)
|
||||
{
|
||||
if (GET_PROTOCOL_MINOR(getProtocol()) >= 0x16) {
|
||||
|
|
@ -318,8 +299,8 @@ StorePathSet RemoteStore::queryDerivationOutputs(const StorePath & path)
|
|||
return WorkerProto::Serialise<StorePathSet>::read(*this, *conn);
|
||||
}
|
||||
|
||||
|
||||
std::map<std::string, std::optional<StorePath>> RemoteStore::queryPartialDerivationOutputMap(const StorePath & path, Store * evalStore_)
|
||||
std::map<std::string, std::optional<StorePath>>
|
||||
RemoteStore::queryPartialDerivationOutputMap(const StorePath & path, Store * evalStore_)
|
||||
{
|
||||
if (GET_PROTOCOL_MINOR(getProtocol()) >= 0x16) {
|
||||
if (!evalStore_) {
|
||||
|
|
@ -358,28 +339,25 @@ std::optional<StorePath> RemoteStore::queryPathFromHashPart(const std::string &
|
|||
conn->to << WorkerProto::Op::QueryPathFromHashPart << hashPart;
|
||||
conn.processStderr();
|
||||
Path path = readString(conn->from);
|
||||
if (path.empty()) return {};
|
||||
if (path.empty())
|
||||
return {};
|
||||
return parseStorePath(path);
|
||||
}
|
||||
|
||||
|
||||
ref<const ValidPathInfo> RemoteStore::addCAToStore(
|
||||
Source & dump,
|
||||
std::string_view name,
|
||||
ContentAddressMethod caMethod,
|
||||
HashAlgorithm hashAlgo,
|
||||
const StorePathSet & references,
|
||||
RepairFlag repair)
|
||||
Source & dump,
|
||||
std::string_view name,
|
||||
ContentAddressMethod caMethod,
|
||||
HashAlgorithm hashAlgo,
|
||||
const StorePathSet & references,
|
||||
RepairFlag repair)
|
||||
{
|
||||
std::optional<ConnectionHandle> conn_(getConnection());
|
||||
auto & conn = *conn_;
|
||||
|
||||
if (GET_PROTOCOL_MINOR(conn->protoVersion) >= 25) {
|
||||
|
||||
conn->to
|
||||
<< WorkerProto::Op::AddToStore
|
||||
<< name
|
||||
<< caMethod.renderWithAlgo(hashAlgo);
|
||||
conn->to << WorkerProto::Op::AddToStore << name << caMethod.renderWithAlgo(hashAlgo);
|
||||
WorkerProto::write(*this, *conn, references);
|
||||
conn->to << repair;
|
||||
|
||||
|
|
@ -387,66 +365,63 @@ ref<const ValidPathInfo> RemoteStore::addCAToStore(
|
|||
connections->incCapacity();
|
||||
{
|
||||
Finally cleanup([&]() { connections->decCapacity(); });
|
||||
conn.withFramedSink([&](Sink & sink) {
|
||||
dump.drainInto(sink);
|
||||
});
|
||||
conn.withFramedSink([&](Sink & sink) { dump.drainInto(sink); });
|
||||
}
|
||||
|
||||
return make_ref<ValidPathInfo>(
|
||||
WorkerProto::Serialise<ValidPathInfo>::read(*this, *conn));
|
||||
}
|
||||
else {
|
||||
if (repair) throw Error("repairing is not supported when building through the Nix daemon protocol < 1.25");
|
||||
return make_ref<ValidPathInfo>(WorkerProto::Serialise<ValidPathInfo>::read(*this, *conn));
|
||||
} else {
|
||||
if (repair)
|
||||
throw Error("repairing is not supported when building through the Nix daemon protocol < 1.25");
|
||||
|
||||
switch (caMethod.raw) {
|
||||
case ContentAddressMethod::Raw::Text:
|
||||
{
|
||||
if (hashAlgo != HashAlgorithm::SHA256)
|
||||
throw UnimplementedError("When adding text-hashed data called '%s', only SHA-256 is supported but '%s' was given",
|
||||
name, printHashAlgo(hashAlgo));
|
||||
std::string s = dump.drain();
|
||||
conn->to << WorkerProto::Op::AddTextToStore << name << s;
|
||||
WorkerProto::write(*this, *conn, references);
|
||||
conn.processStderr();
|
||||
break;
|
||||
}
|
||||
case ContentAddressMethod::Raw::Flat:
|
||||
case ContentAddressMethod::Raw::NixArchive:
|
||||
case ContentAddressMethod::Raw::Git:
|
||||
default:
|
||||
{
|
||||
auto fim = caMethod.getFileIngestionMethod();
|
||||
conn->to
|
||||
<< WorkerProto::Op::AddToStore
|
||||
<< name
|
||||
<< ((hashAlgo == HashAlgorithm::SHA256 && fim == FileIngestionMethod::NixArchive) ? 0 : 1) /* backwards compatibility hack */
|
||||
<< (fim == FileIngestionMethod::NixArchive ? 1 : 0)
|
||||
<< printHashAlgo(hashAlgo);
|
||||
case ContentAddressMethod::Raw::Text: {
|
||||
if (hashAlgo != HashAlgorithm::SHA256)
|
||||
throw UnimplementedError(
|
||||
"When adding text-hashed data called '%s', only SHA-256 is supported but '%s' was given",
|
||||
name,
|
||||
printHashAlgo(hashAlgo));
|
||||
std::string s = dump.drain();
|
||||
conn->to << WorkerProto::Op::AddTextToStore << name << s;
|
||||
WorkerProto::write(*this, *conn, references);
|
||||
conn.processStderr();
|
||||
break;
|
||||
}
|
||||
case ContentAddressMethod::Raw::Flat:
|
||||
case ContentAddressMethod::Raw::NixArchive:
|
||||
case ContentAddressMethod::Raw::Git:
|
||||
default: {
|
||||
auto fim = caMethod.getFileIngestionMethod();
|
||||
conn->to << WorkerProto::Op::AddToStore << name
|
||||
<< ((hashAlgo == HashAlgorithm::SHA256 && fim == FileIngestionMethod::NixArchive)
|
||||
? 0
|
||||
: 1) /* backwards compatibility hack */
|
||||
<< (fim == FileIngestionMethod::NixArchive ? 1 : 0) << printHashAlgo(hashAlgo);
|
||||
|
||||
try {
|
||||
conn->to.written = 0;
|
||||
connections->incCapacity();
|
||||
{
|
||||
Finally cleanup([&]() { connections->decCapacity(); });
|
||||
if (fim == FileIngestionMethod::NixArchive) {
|
||||
dump.drainInto(conn->to);
|
||||
} else {
|
||||
std::string contents = dump.drain();
|
||||
dumpString(contents, conn->to);
|
||||
}
|
||||
try {
|
||||
conn->to.written = 0;
|
||||
connections->incCapacity();
|
||||
{
|
||||
Finally cleanup([&]() { connections->decCapacity(); });
|
||||
if (fim == FileIngestionMethod::NixArchive) {
|
||||
dump.drainInto(conn->to);
|
||||
} else {
|
||||
std::string contents = dump.drain();
|
||||
dumpString(contents, conn->to);
|
||||
}
|
||||
conn.processStderr();
|
||||
} catch (SysError & e) {
|
||||
/* Daemon closed while we were sending the path. Probably OOM
|
||||
or I/O error. */
|
||||
if (e.errNo == EPIPE)
|
||||
try {
|
||||
conn.processStderr();
|
||||
} catch (EndOfFile & e) { }
|
||||
throw;
|
||||
}
|
||||
break;
|
||||
conn.processStderr();
|
||||
} catch (SysError & e) {
|
||||
/* Daemon closed while we were sending the path. Probably OOM
|
||||
or I/O error. */
|
||||
if (e.errNo == EPIPE)
|
||||
try {
|
||||
conn.processStderr();
|
||||
} catch (EndOfFile & e) {
|
||||
}
|
||||
throw;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
auto path = parseStorePath(readString(conn->from));
|
||||
// Release our connection to prevent a deadlock in queryPathInfo().
|
||||
|
|
@ -455,7 +430,6 @@ ref<const ValidPathInfo> RemoteStore::addCAToStore(
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
StorePath RemoteStore::addToStoreFromDump(
|
||||
Source & dump,
|
||||
std::string_view name,
|
||||
|
|
@ -485,9 +459,7 @@ StorePath RemoteStore::addToStoreFromDump(
|
|||
return addCAToStore(dump, name, hashMethod, hashAlgo, references, repair)->path;
|
||||
}
|
||||
|
||||
|
||||
void RemoteStore::addToStore(const ValidPathInfo & info, Source & source,
|
||||
RepairFlag repair, CheckSigsFlag checkSigs)
|
||||
void RemoteStore::addToStore(const ValidPathInfo & info, Source & source, RepairFlag repair, CheckSigsFlag checkSigs)
|
||||
{
|
||||
auto conn(getConnection());
|
||||
|
||||
|
|
@ -496,33 +468,25 @@ void RemoteStore::addToStore(const ValidPathInfo & info, Source & source,
|
|||
sink << 1 // == path follows
|
||||
;
|
||||
copyNAR(source, sink);
|
||||
sink
|
||||
<< exportMagic
|
||||
<< printStorePath(info.path);
|
||||
sink << exportMagic << printStorePath(info.path);
|
||||
WorkerProto::write(*this, *conn, info.references);
|
||||
sink
|
||||
<< (info.deriver ? printStorePath(*info.deriver) : "")
|
||||
<< 0 // == no legacy signature
|
||||
<< 0 // == no path follows
|
||||
sink << (info.deriver ? printStorePath(*info.deriver) : "") << 0 // == no legacy signature
|
||||
<< 0 // == no path follows
|
||||
;
|
||||
});
|
||||
conn->importPaths(*this, &conn.daemonException, *source2);
|
||||
}
|
||||
|
||||
else {
|
||||
conn->to << WorkerProto::Op::AddToStoreNar
|
||||
<< printStorePath(info.path)
|
||||
conn->to << WorkerProto::Op::AddToStoreNar << printStorePath(info.path)
|
||||
<< (info.deriver ? printStorePath(*info.deriver) : "")
|
||||
<< info.narHash.to_string(HashFormat::Base16, false);
|
||||
WorkerProto::write(*this, *conn, info.references);
|
||||
conn->to << info.registrationTime << info.narSize
|
||||
<< info.ultimate << info.sigs << renderContentAddress(info.ca)
|
||||
conn->to << info.registrationTime << info.narSize << info.ultimate << info.sigs << renderContentAddress(info.ca)
|
||||
<< repair << !checkSigs;
|
||||
|
||||
if (GET_PROTOCOL_MINOR(conn->protoVersion) >= 23) {
|
||||
conn.withFramedSink([&](Sink & sink) {
|
||||
copyNAR(source, sink);
|
||||
});
|
||||
conn.withFramedSink([&](Sink & sink) { copyNAR(source, sink); });
|
||||
} else if (GET_PROTOCOL_MINOR(conn->protoVersion) >= 21) {
|
||||
conn.processStderr(0, &source);
|
||||
} else {
|
||||
|
|
@ -532,12 +496,8 @@ void RemoteStore::addToStore(const ValidPathInfo & info, Source & source,
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void RemoteStore::addMultipleToStore(
|
||||
PathsSource && pathsToCopy,
|
||||
Activity & act,
|
||||
RepairFlag repair,
|
||||
CheckSigsFlag checkSigs)
|
||||
PathsSource && pathsToCopy, Activity & act, RepairFlag repair, CheckSigsFlag checkSigs)
|
||||
{
|
||||
// `addMultipleToStore` is single threaded
|
||||
size_t bytesExpected = 0;
|
||||
|
|
@ -555,12 +515,13 @@ void RemoteStore::addMultipleToStore(
|
|||
act.progress(nrTotal - pathsToCopy.size(), nrTotal, size_t(1), size_t(0));
|
||||
|
||||
auto & [pathInfo, pathSource] = pathsToCopy.back();
|
||||
WorkerProto::Serialise<ValidPathInfo>::write(*this,
|
||||
WorkerProto::WriteConn {
|
||||
.to = sink,
|
||||
.version = 16,
|
||||
},
|
||||
pathInfo);
|
||||
WorkerProto::Serialise<ValidPathInfo>::write(
|
||||
*this,
|
||||
WorkerProto::WriteConn{
|
||||
.to = sink,
|
||||
.version = 16,
|
||||
},
|
||||
pathInfo);
|
||||
pathSource->drainInto(sink);
|
||||
pathsToCopy.pop_back();
|
||||
}
|
||||
|
|
@ -569,25 +530,16 @@ void RemoteStore::addMultipleToStore(
|
|||
addMultipleToStore(*source, repair, checkSigs);
|
||||
}
|
||||
|
||||
void RemoteStore::addMultipleToStore(
|
||||
Source & source,
|
||||
RepairFlag repair,
|
||||
CheckSigsFlag checkSigs)
|
||||
void RemoteStore::addMultipleToStore(Source & source, RepairFlag repair, CheckSigsFlag checkSigs)
|
||||
{
|
||||
if (GET_PROTOCOL_MINOR(getConnection()->protoVersion) >= 32) {
|
||||
auto conn(getConnection());
|
||||
conn->to
|
||||
<< WorkerProto::Op::AddMultipleToStore
|
||||
<< repair
|
||||
<< !checkSigs;
|
||||
conn.withFramedSink([&](Sink & sink) {
|
||||
source.drainInto(sink);
|
||||
});
|
||||
conn->to << WorkerProto::Op::AddMultipleToStore << repair << !checkSigs;
|
||||
conn.withFramedSink([&](Sink & sink) { source.drainInto(sink); });
|
||||
} else
|
||||
Store::addMultipleToStore(source, repair, checkSigs);
|
||||
}
|
||||
|
||||
|
||||
void RemoteStore::registerDrvOutput(const Realisation & info)
|
||||
{
|
||||
auto conn(getConnection());
|
||||
|
|
@ -601,8 +553,8 @@ void RemoteStore::registerDrvOutput(const Realisation & info)
|
|||
conn.processStderr();
|
||||
}
|
||||
|
||||
void RemoteStore::queryRealisationUncached(const DrvOutput & id,
|
||||
Callback<std::shared_ptr<const Realisation>> callback) noexcept
|
||||
void RemoteStore::queryRealisationUncached(
|
||||
const DrvOutput & id, Callback<std::shared_ptr<const Realisation>> callback) noexcept
|
||||
{
|
||||
try {
|
||||
auto conn(getConnection());
|
||||
|
|
@ -618,14 +570,12 @@ void RemoteStore::queryRealisationUncached(const DrvOutput & id,
|
|||
|
||||
auto real = [&]() -> std::shared_ptr<const Realisation> {
|
||||
if (GET_PROTOCOL_MINOR(conn->protoVersion) < 31) {
|
||||
auto outPaths = WorkerProto::Serialise<std::set<StorePath>>::read(
|
||||
*this, *conn);
|
||||
auto outPaths = WorkerProto::Serialise<std::set<StorePath>>::read(*this, *conn);
|
||||
if (outPaths.empty())
|
||||
return nullptr;
|
||||
return std::make_shared<const Realisation>(Realisation { .id = id, .outPath = *outPaths.begin() });
|
||||
return std::make_shared<const Realisation>(Realisation{.id = id, .outPath = *outPaths.begin()});
|
||||
} else {
|
||||
auto realisations = WorkerProto::Serialise<std::set<Realisation>>::read(
|
||||
*this, *conn);
|
||||
auto realisations = WorkerProto::Serialise<std::set<Realisation>>::read(*this, *conn);
|
||||
if (realisations.empty())
|
||||
return nullptr;
|
||||
return std::make_shared<const Realisation>(*realisations.begin());
|
||||
|
|
@ -633,32 +583,33 @@ void RemoteStore::queryRealisationUncached(const DrvOutput & id,
|
|||
}();
|
||||
|
||||
callback(std::shared_ptr<const Realisation>(real));
|
||||
} catch (...) { return callback.rethrow(); }
|
||||
} catch (...) {
|
||||
return callback.rethrow();
|
||||
}
|
||||
}
|
||||
|
||||
void RemoteStore::copyDrvsFromEvalStore(
|
||||
const std::vector<DerivedPath> & paths,
|
||||
std::shared_ptr<Store> evalStore)
|
||||
void RemoteStore::copyDrvsFromEvalStore(const std::vector<DerivedPath> & paths, std::shared_ptr<Store> evalStore)
|
||||
{
|
||||
if (evalStore && evalStore.get() != this) {
|
||||
/* The remote doesn't have a way to access evalStore, so copy
|
||||
the .drvs. */
|
||||
RealisedPath::Set drvPaths2;
|
||||
for (const auto & i : paths) {
|
||||
std::visit(overloaded {
|
||||
[&](const DerivedPath::Opaque & bp) {
|
||||
// Do nothing, path is hopefully there already
|
||||
std::visit(
|
||||
overloaded{
|
||||
[&](const DerivedPath::Opaque & bp) {
|
||||
// Do nothing, path is hopefully there already
|
||||
},
|
||||
[&](const DerivedPath::Built & bp) { drvPaths2.insert(bp.drvPath->getBaseStorePath()); },
|
||||
},
|
||||
[&](const DerivedPath::Built & bp) {
|
||||
drvPaths2.insert(bp.drvPath->getBaseStorePath());
|
||||
},
|
||||
}, i.raw());
|
||||
i.raw());
|
||||
}
|
||||
copyClosure(*evalStore, *this, drvPaths2);
|
||||
}
|
||||
}
|
||||
|
||||
void RemoteStore::buildPaths(const std::vector<DerivedPath> & drvPaths, BuildMode buildMode, std::shared_ptr<Store> evalStore)
|
||||
void RemoteStore::buildPaths(
|
||||
const std::vector<DerivedPath> & drvPaths, BuildMode buildMode, std::shared_ptr<Store> evalStore)
|
||||
{
|
||||
copyDrvsFromEvalStore(drvPaths, evalStore);
|
||||
|
||||
|
|
@ -678,9 +629,7 @@ void RemoteStore::buildPaths(const std::vector<DerivedPath> & drvPaths, BuildMod
|
|||
}
|
||||
|
||||
std::vector<KeyedBuildResult> RemoteStore::buildPathsWithResults(
|
||||
const std::vector<DerivedPath> & paths,
|
||||
BuildMode buildMode,
|
||||
std::shared_ptr<Store> evalStore)
|
||||
const std::vector<DerivedPath> & paths, BuildMode buildMode, std::shared_ptr<Store> evalStore)
|
||||
{
|
||||
copyDrvsFromEvalStore(paths, evalStore);
|
||||
|
||||
|
|
@ -705,20 +654,19 @@ std::vector<KeyedBuildResult> RemoteStore::buildPathsWithResults(
|
|||
|
||||
for (auto & path : paths) {
|
||||
std::visit(
|
||||
overloaded {
|
||||
overloaded{
|
||||
[&](const DerivedPath::Opaque & bo) {
|
||||
results.push_back(KeyedBuildResult {
|
||||
{
|
||||
.status = BuildResult::Substituted,
|
||||
},
|
||||
/* .path = */ bo,
|
||||
});
|
||||
results.push_back(
|
||||
KeyedBuildResult{
|
||||
{
|
||||
.status = BuildResult::Substituted,
|
||||
},
|
||||
/* .path = */ bo,
|
||||
});
|
||||
},
|
||||
[&](const DerivedPath::Built & bfd) {
|
||||
KeyedBuildResult res {
|
||||
{
|
||||
.status = BuildResult::Built
|
||||
},
|
||||
KeyedBuildResult res{
|
||||
{.status = BuildResult::Built},
|
||||
/* .path = */ bfd,
|
||||
};
|
||||
|
||||
|
|
@ -732,18 +680,18 @@ std::vector<KeyedBuildResult> RemoteStore::buildPathsWithResults(
|
|||
if (!outputHash)
|
||||
throw Error(
|
||||
"the derivation '%s' doesn't have an output named '%s'",
|
||||
printStorePath(drvPath), output);
|
||||
auto outputId = DrvOutput{ *outputHash, output };
|
||||
printStorePath(drvPath),
|
||||
output);
|
||||
auto outputId = DrvOutput{*outputHash, output};
|
||||
if (experimentalFeatureSettings.isEnabled(Xp::CaDerivations)) {
|
||||
auto realisation =
|
||||
queryRealisation(outputId);
|
||||
auto realisation = queryRealisation(outputId);
|
||||
if (!realisation)
|
||||
throw MissingRealisation(outputId);
|
||||
res.builtOutputs.emplace(output, *realisation);
|
||||
} else {
|
||||
res.builtOutputs.emplace(
|
||||
output,
|
||||
Realisation {
|
||||
Realisation{
|
||||
.id = outputId,
|
||||
.outPath = outputPath,
|
||||
});
|
||||
|
|
@ -751,8 +699,7 @@ std::vector<KeyedBuildResult> RemoteStore::buildPathsWithResults(
|
|||
}
|
||||
|
||||
results.push_back(res);
|
||||
}
|
||||
},
|
||||
}},
|
||||
path.raw());
|
||||
}
|
||||
|
||||
|
|
@ -760,9 +707,7 @@ std::vector<KeyedBuildResult> RemoteStore::buildPathsWithResults(
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
BuildResult RemoteStore::buildDerivation(const StorePath & drvPath, const BasicDerivation & drv,
|
||||
BuildMode buildMode)
|
||||
BuildResult RemoteStore::buildDerivation(const StorePath & drvPath, const BasicDerivation & drv, BuildMode buildMode)
|
||||
{
|
||||
auto conn(getConnection());
|
||||
conn->putBuildDerivationRequest(*this, &conn.daemonException, drvPath, drv, buildMode);
|
||||
|
|
@ -770,7 +715,6 @@ BuildResult RemoteStore::buildDerivation(const StorePath & drvPath, const BasicD
|
|||
return WorkerProto::Serialise<BuildResult>::read(*this, *conn);
|
||||
}
|
||||
|
||||
|
||||
void RemoteStore::ensurePath(const StorePath & path)
|
||||
{
|
||||
auto conn(getConnection());
|
||||
|
|
@ -779,14 +723,12 @@ void RemoteStore::ensurePath(const StorePath & path)
|
|||
readInt(conn->from);
|
||||
}
|
||||
|
||||
|
||||
void RemoteStore::addTempRoot(const StorePath & path)
|
||||
{
|
||||
auto conn(getConnection());
|
||||
conn->addTempRoot(*this, &conn.daemonException, path);
|
||||
}
|
||||
|
||||
|
||||
Roots RemoteStore::findRoots(bool censor)
|
||||
{
|
||||
auto conn(getConnection());
|
||||
|
|
@ -802,18 +744,16 @@ Roots RemoteStore::findRoots(bool censor)
|
|||
return result;
|
||||
}
|
||||
|
||||
|
||||
void RemoteStore::collectGarbage(const GCOptions & options, GCResults & results)
|
||||
{
|
||||
auto conn(getConnection());
|
||||
|
||||
conn->to
|
||||
<< WorkerProto::Op::CollectGarbage << options.action;
|
||||
conn->to << WorkerProto::Op::CollectGarbage << options.action;
|
||||
WorkerProto::write(*this, *conn, options.pathsToDelete);
|
||||
conn->to << options.ignoreLiveness
|
||||
<< options.maxFreed
|
||||
/* removed options */
|
||||
<< 0 << 0 << 0;
|
||||
<< options.maxFreed
|
||||
/* removed options */
|
||||
<< 0 << 0 << 0;
|
||||
|
||||
conn.processStderr();
|
||||
|
||||
|
|
@ -827,7 +767,6 @@ void RemoteStore::collectGarbage(const GCOptions & options, GCResults & results)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void RemoteStore::optimiseStore()
|
||||
{
|
||||
auto conn(getConnection());
|
||||
|
|
@ -836,7 +775,6 @@ void RemoteStore::optimiseStore()
|
|||
readInt(conn->from);
|
||||
}
|
||||
|
||||
|
||||
bool RemoteStore::verifyStore(bool checkContents, RepairFlag repair)
|
||||
{
|
||||
auto conn(getConnection());
|
||||
|
|
@ -845,7 +783,6 @@ bool RemoteStore::verifyStore(bool checkContents, RepairFlag repair)
|
|||
return readInt(conn->from);
|
||||
}
|
||||
|
||||
|
||||
void RemoteStore::addSignatures(const StorePath & storePath, const StringSet & sigs)
|
||||
{
|
||||
auto conn(getConnection());
|
||||
|
|
@ -854,7 +791,6 @@ void RemoteStore::addSignatures(const StorePath & storePath, const StringSet & s
|
|||
readInt(conn->from);
|
||||
}
|
||||
|
||||
|
||||
MissingPaths RemoteStore::queryMissing(const std::vector<DerivedPath> & targets)
|
||||
{
|
||||
{
|
||||
|
|
@ -874,36 +810,30 @@ MissingPaths RemoteStore::queryMissing(const std::vector<DerivedPath> & targets)
|
|||
return res;
|
||||
}
|
||||
|
||||
fallback:
|
||||
fallback:
|
||||
return Store::queryMissing(targets);
|
||||
}
|
||||
|
||||
|
||||
void RemoteStore::addBuildLog(const StorePath & drvPath, std::string_view log)
|
||||
{
|
||||
auto conn(getConnection());
|
||||
conn->to << WorkerProto::Op::AddBuildLog << drvPath.to_string();
|
||||
StringSource source(log);
|
||||
conn.withFramedSink([&](Sink & sink) {
|
||||
source.drainInto(sink);
|
||||
});
|
||||
conn.withFramedSink([&](Sink & sink) { source.drainInto(sink); });
|
||||
readInt(conn->from);
|
||||
}
|
||||
|
||||
|
||||
std::optional<std::string> RemoteStore::getVersion()
|
||||
{
|
||||
auto conn(getConnection());
|
||||
return conn->daemonNixVersion;
|
||||
}
|
||||
|
||||
|
||||
void RemoteStore::connect()
|
||||
{
|
||||
auto conn(getConnection());
|
||||
}
|
||||
|
||||
|
||||
unsigned int RemoteStore::getProtocol()
|
||||
{
|
||||
auto conn(connections->get());
|
||||
|
|
@ -924,9 +854,7 @@ void RemoteStore::flushBadConnections()
|
|||
void RemoteStore::narFromPath(const StorePath & path, Sink & sink)
|
||||
{
|
||||
auto conn(getConnection());
|
||||
conn->narFromPath(*this, &conn.daemonException, path, [&](Source & source) {
|
||||
copyNAR(conn->from, sink);
|
||||
});
|
||||
conn->narFromPath(*this, &conn.daemonException, path, [&](Source & source) { copyNAR(conn->from, sink); });
|
||||
}
|
||||
|
||||
ref<SourceAccessor> RemoteStore::getFSAccessor(bool requireValidPath)
|
||||
|
|
@ -951,4 +879,4 @@ void RemoteStore::ConnectionHandle::withFramedSink(std::function<void(Sink & sin
|
|||
processStderr(nullptr, nullptr, false);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace nix
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue