mirror of
https://github.com/NixOS/nix.git
synced 2025-11-21 09:49:36 +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
|
|
@ -16,10 +16,7 @@
|
|||
|
||||
namespace nix {
|
||||
|
||||
LegacySSHStoreConfig::LegacySSHStoreConfig(
|
||||
std::string_view scheme,
|
||||
std::string_view authority,
|
||||
const Params & params)
|
||||
LegacySSHStoreConfig::LegacySSHStoreConfig(std::string_view scheme, std::string_view authority, const Params & params)
|
||||
: StoreConfig(params)
|
||||
, CommonSSHStoreConfig(scheme, authority, params)
|
||||
{
|
||||
|
|
@ -28,34 +25,31 @@ LegacySSHStoreConfig::LegacySSHStoreConfig(
|
|||
std::string LegacySSHStoreConfig::doc()
|
||||
{
|
||||
return
|
||||
#include "legacy-ssh-store.md"
|
||||
;
|
||||
#include "legacy-ssh-store.md"
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
struct LegacySSHStore::Connection : public ServeProto::BasicClientConnection
|
||||
{
|
||||
std::unique_ptr<SSHMaster::Connection> sshConn;
|
||||
bool good = true;
|
||||
};
|
||||
|
||||
|
||||
LegacySSHStore::LegacySSHStore(ref<const Config> config)
|
||||
: Store{*config}
|
||||
, config{config}
|
||||
, connections(make_ref<Pool<Connection>>(
|
||||
std::max(1, (int) config->maxConnections),
|
||||
[this]() { return openConnection(); },
|
||||
[](const ref<Connection> & r) { return r->good; }
|
||||
))
|
||||
, connections(
|
||||
make_ref<Pool<Connection>>(
|
||||
std::max(1, (int) config->maxConnections),
|
||||
[this]() { return openConnection(); },
|
||||
[](const ref<Connection> & r) { return r->good; }))
|
||||
, master(config->createSSHMaster(
|
||||
// Use SSH master only if using more than 1 connection.
|
||||
connections->capacity() > 1,
|
||||
config->logFD))
|
||||
// Use SSH master only if using more than 1 connection.
|
||||
connections->capacity() > 1,
|
||||
config->logFD))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ref<LegacySSHStore::Connection> LegacySSHStore::openConnection()
|
||||
{
|
||||
auto conn = make_ref<Connection>();
|
||||
|
|
@ -76,8 +70,8 @@ ref<LegacySSHStore::Connection> LegacySSHStore::openConnection()
|
|||
StringSink saved;
|
||||
TeeSource tee(conn->from, saved);
|
||||
try {
|
||||
conn->remoteVersion = ServeProto::BasicClientConnection::handshake(
|
||||
conn->to, tee, SERVE_PROTOCOL_VERSION, config->host);
|
||||
conn->remoteVersion =
|
||||
ServeProto::BasicClientConnection::handshake(conn->to, tee, SERVE_PROTOCOL_VERSION, config->host);
|
||||
} catch (SerialisationError & e) {
|
||||
// in.close(): Don't let the remote block on us not writing.
|
||||
conn->sshConn->in.close();
|
||||
|
|
@ -85,8 +79,7 @@ ref<LegacySSHStore::Connection> LegacySSHStore::openConnection()
|
|||
NullSink nullSink;
|
||||
tee.drainInto(nullSink);
|
||||
}
|
||||
throw Error("'nix-store --serve' protocol mismatch from '%s', got '%s'",
|
||||
config->host, chomp(saved.s));
|
||||
throw Error("'nix-store --serve' protocol mismatch from '%s', got '%s'", config->host, chomp(saved.s));
|
||||
} catch (EndOfFile & e) {
|
||||
throw Error("cannot connect to '%1%'", config->host);
|
||||
}
|
||||
|
|
@ -94,14 +87,12 @@ ref<LegacySSHStore::Connection> LegacySSHStore::openConnection()
|
|||
return conn;
|
||||
};
|
||||
|
||||
|
||||
std::string LegacySSHStore::getUri()
|
||||
{
|
||||
return *Config::uriSchemes().begin() + "://" + config->host;
|
||||
}
|
||||
|
||||
std::map<StorePath, UnkeyedValidPathInfo> LegacySSHStore::queryPathInfosUncached(
|
||||
const StorePathSet & paths)
|
||||
std::map<StorePath, UnkeyedValidPathInfo> LegacySSHStore::queryPathInfosUncached(const StorePathSet & paths)
|
||||
{
|
||||
auto conn(connections->get());
|
||||
|
||||
|
|
@ -120,8 +111,8 @@ std::map<StorePath, UnkeyedValidPathInfo> LegacySSHStore::queryPathInfosUncached
|
|||
return infos;
|
||||
}
|
||||
|
||||
void LegacySSHStore::queryPathInfoUncached(const StorePath & path,
|
||||
Callback<std::shared_ptr<const ValidPathInfo>> callback) noexcept
|
||||
void LegacySSHStore::queryPathInfoUncached(
|
||||
const StorePath & path, Callback<std::shared_ptr<const ValidPathInfo>> callback) noexcept
|
||||
{
|
||||
try {
|
||||
auto infos = queryPathInfosUncached({path});
|
||||
|
|
@ -133,20 +124,17 @@ void LegacySSHStore::queryPathInfoUncached(const StorePath & path,
|
|||
auto & [path2, info] = *infos.begin();
|
||||
|
||||
assert(path == path2);
|
||||
return callback(std::make_shared<ValidPathInfo>(
|
||||
std::move(path),
|
||||
std::move(info)
|
||||
));
|
||||
return callback(std::make_shared<ValidPathInfo>(std::move(path), std::move(info)));
|
||||
}
|
||||
default:
|
||||
throw Error("More path infos returned than queried");
|
||||
}
|
||||
} catch (...) { callback.rethrow(); }
|
||||
} catch (...) {
|
||||
callback.rethrow();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void LegacySSHStore::addToStore(const ValidPathInfo & info, Source & source,
|
||||
RepairFlag repair, CheckSigsFlag checkSigs)
|
||||
void LegacySSHStore::addToStore(const ValidPathInfo & info, Source & source, RepairFlag repair, CheckSigsFlag checkSigs)
|
||||
{
|
||||
debug("adding path '%s' to remote host '%s'", printStorePath(info.path), config->host);
|
||||
|
||||
|
|
@ -154,18 +142,12 @@ void LegacySSHStore::addToStore(const ValidPathInfo & info, Source & source,
|
|||
|
||||
if (GET_PROTOCOL_MINOR(conn->remoteVersion) >= 5) {
|
||||
|
||||
conn->to
|
||||
<< ServeProto::Command::AddToStoreNar
|
||||
<< printStorePath(info.path)
|
||||
<< (info.deriver ? printStorePath(*info.deriver) : "")
|
||||
<< info.narHash.to_string(HashFormat::Base16, false);
|
||||
conn->to << ServeProto::Command::AddToStoreNar << printStorePath(info.path)
|
||||
<< (info.deriver ? printStorePath(*info.deriver) : "")
|
||||
<< info.narHash.to_string(HashFormat::Base16, false);
|
||||
ServeProto::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);
|
||||
try {
|
||||
copyNAR(source, conn->to);
|
||||
} catch (...) {
|
||||
|
|
@ -186,35 +168,24 @@ void LegacySSHStore::addToStore(const ValidPathInfo & info, Source & source,
|
|||
conn->good = false;
|
||||
throw;
|
||||
}
|
||||
sink
|
||||
<< exportMagic
|
||||
<< printStorePath(info.path);
|
||||
sink << exportMagic << printStorePath(info.path);
|
||||
ServeProto::write(*this, *conn, info.references);
|
||||
sink
|
||||
<< (info.deriver ? printStorePath(*info.deriver) : "")
|
||||
<< 0
|
||||
<< 0;
|
||||
sink << (info.deriver ? printStorePath(*info.deriver) : "") << 0 << 0;
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void LegacySSHStore::narFromPath(const StorePath & path, Sink & sink)
|
||||
{
|
||||
narFromPath(path, [&](auto & source) {
|
||||
copyNAR(source, sink);
|
||||
});
|
||||
narFromPath(path, [&](auto & source) { copyNAR(source, sink); });
|
||||
}
|
||||
|
||||
|
||||
void LegacySSHStore::narFromPath(const StorePath & path, std::function<void(Source &)> fun)
|
||||
{
|
||||
auto conn(connections->get());
|
||||
conn->narFromPath(*this, path, fun);
|
||||
}
|
||||
|
||||
|
||||
static ServeProto::BuildOptions buildSettings()
|
||||
{
|
||||
return {
|
||||
|
|
@ -227,9 +198,7 @@ static ServeProto::BuildOptions buildSettings()
|
|||
};
|
||||
}
|
||||
|
||||
|
||||
BuildResult LegacySSHStore::buildDerivation(const StorePath & drvPath, const BasicDerivation & drv,
|
||||
BuildMode buildMode)
|
||||
BuildResult LegacySSHStore::buildDerivation(const StorePath & drvPath, const BasicDerivation & drv, BuildMode buildMode)
|
||||
{
|
||||
auto conn(connections->get());
|
||||
|
||||
|
|
@ -239,20 +208,17 @@ BuildResult LegacySSHStore::buildDerivation(const StorePath & drvPath, const Bas
|
|||
}
|
||||
|
||||
std::function<BuildResult()> LegacySSHStore::buildDerivationAsync(
|
||||
const StorePath & drvPath, const BasicDerivation & drv,
|
||||
const ServeProto::BuildOptions & options)
|
||||
const StorePath & drvPath, const BasicDerivation & drv, const ServeProto::BuildOptions & options)
|
||||
{
|
||||
// Until we have C++23 std::move_only_function
|
||||
auto conn = std::make_shared<Pool<Connection>::Handle>(connections->get());
|
||||
(*conn)->putBuildDerivationRequest(*this, drvPath, drv, options);
|
||||
|
||||
return [this,conn]() -> BuildResult {
|
||||
return (*conn)->getBuildDerivationResponse(*this);
|
||||
};
|
||||
return [this, conn]() -> BuildResult { return (*conn)->getBuildDerivationResponse(*this); };
|
||||
}
|
||||
|
||||
|
||||
void LegacySSHStore::buildPaths(const std::vector<DerivedPath> & drvPaths, BuildMode buildMode, std::shared_ptr<Store> evalStore)
|
||||
void LegacySSHStore::buildPaths(
|
||||
const std::vector<DerivedPath> & drvPaths, BuildMode buildMode, std::shared_ptr<Store> evalStore)
|
||||
{
|
||||
if (evalStore && evalStore.get() != this)
|
||||
throw Error("building on an SSH store is incompatible with '--eval-store'");
|
||||
|
|
@ -263,17 +229,20 @@ void LegacySSHStore::buildPaths(const std::vector<DerivedPath> & drvPaths, Build
|
|||
Strings ss;
|
||||
for (auto & p : drvPaths) {
|
||||
auto sOrDrvPath = StorePathWithOutputs::tryFromDerivedPath(p);
|
||||
std::visit(overloaded {
|
||||
[&](const StorePathWithOutputs & s) {
|
||||
ss.push_back(s.to_string(*this));
|
||||
std::visit(
|
||||
overloaded{
|
||||
[&](const StorePathWithOutputs & s) { ss.push_back(s.to_string(*this)); },
|
||||
[&](const StorePath & drvPath) {
|
||||
throw Error(
|
||||
"wanted to fetch '%s' but the legacy ssh protocol doesn't support merely substituting drv files via the build paths command. It would build them instead. Try using ssh-ng://",
|
||||
printStorePath(drvPath));
|
||||
},
|
||||
[&](std::monostate) {
|
||||
throw Error(
|
||||
"wanted build derivation that is itself a build product, but the legacy ssh protocol doesn't support that. Try using ssh-ng://");
|
||||
},
|
||||
},
|
||||
[&](const StorePath & drvPath) {
|
||||
throw Error("wanted to fetch '%s' but the legacy ssh protocol doesn't support merely substituting drv files via the build paths command. It would build them instead. Try using ssh-ng://", printStorePath(drvPath));
|
||||
},
|
||||
[&](std::monostate) {
|
||||
throw Error("wanted build derivation that is itself a build product, but the legacy ssh protocol doesn't support that. Try using ssh-ng://");
|
||||
},
|
||||
}, sOrDrvPath);
|
||||
sOrDrvPath);
|
||||
}
|
||||
conn->to << ss;
|
||||
|
||||
|
|
@ -290,10 +259,8 @@ void LegacySSHStore::buildPaths(const std::vector<DerivedPath> & drvPaths, Build
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void LegacySSHStore::computeFSClosure(const StorePathSet & paths,
|
||||
StorePathSet & out, bool flipDirection,
|
||||
bool includeOutputs, bool includeDerivers)
|
||||
void LegacySSHStore::computeFSClosure(
|
||||
const StorePathSet & paths, StorePathSet & out, bool flipDirection, bool includeOutputs, bool includeDerivers)
|
||||
{
|
||||
if (flipDirection || includeDerivers) {
|
||||
Store::computeFSClosure(paths, out, flipDirection, includeOutputs, includeDerivers);
|
||||
|
|
@ -302,9 +269,7 @@ void LegacySSHStore::computeFSClosure(const StorePathSet & paths,
|
|||
|
||||
auto conn(connections->get());
|
||||
|
||||
conn->to
|
||||
<< ServeProto::Command::QueryClosure
|
||||
<< includeOutputs;
|
||||
conn->to << ServeProto::Command::QueryClosure << includeOutputs;
|
||||
ServeProto::write(*this, *conn, paths);
|
||||
conn->to.flush();
|
||||
|
||||
|
|
@ -312,25 +277,18 @@ void LegacySSHStore::computeFSClosure(const StorePathSet & paths,
|
|||
out.insert(i);
|
||||
}
|
||||
|
||||
|
||||
StorePathSet LegacySSHStore::queryValidPaths(const StorePathSet & paths,
|
||||
SubstituteFlag maybeSubstitute)
|
||||
StorePathSet LegacySSHStore::queryValidPaths(const StorePathSet & paths, SubstituteFlag maybeSubstitute)
|
||||
{
|
||||
auto conn(connections->get());
|
||||
return conn->queryValidPaths(*this,
|
||||
false, paths, maybeSubstitute);
|
||||
return conn->queryValidPaths(*this, false, paths, maybeSubstitute);
|
||||
}
|
||||
|
||||
|
||||
StorePathSet LegacySSHStore::queryValidPaths(const StorePathSet & paths,
|
||||
bool lock, SubstituteFlag maybeSubstitute)
|
||||
StorePathSet LegacySSHStore::queryValidPaths(const StorePathSet & paths, bool lock, SubstituteFlag maybeSubstitute)
|
||||
{
|
||||
auto conn(connections->get());
|
||||
return conn->queryValidPaths(*this,
|
||||
lock, paths, maybeSubstitute);
|
||||
return conn->queryValidPaths(*this, lock, paths, maybeSubstitute);
|
||||
}
|
||||
|
||||
|
||||
void LegacySSHStore::addMultipleToStoreLegacy(Store & srcStore, const StorePathSet & paths)
|
||||
{
|
||||
auto conn(connections->get());
|
||||
|
|
@ -347,20 +305,17 @@ void LegacySSHStore::addMultipleToStoreLegacy(Store & srcStore, const StorePathS
|
|||
throw Error("remote machine failed to import closure");
|
||||
}
|
||||
|
||||
|
||||
void LegacySSHStore::connect()
|
||||
{
|
||||
auto conn(connections->get());
|
||||
}
|
||||
|
||||
|
||||
unsigned int LegacySSHStore::getProtocol()
|
||||
{
|
||||
auto conn(connections->get());
|
||||
return conn->remoteVersion;
|
||||
}
|
||||
|
||||
|
||||
pid_t LegacySSHStore::getConnectionPid()
|
||||
{
|
||||
auto conn(connections->get());
|
||||
|
|
@ -372,7 +327,6 @@ pid_t LegacySSHStore::getConnectionPid()
|
|||
#endif
|
||||
}
|
||||
|
||||
|
||||
LegacySSHStore::ConnectionStats LegacySSHStore::getConnectionStats()
|
||||
{
|
||||
auto conn(connections->get());
|
||||
|
|
@ -382,7 +336,6 @@ LegacySSHStore::ConnectionStats LegacySSHStore::getConnectionStats()
|
|||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The legacy ssh protocol doesn't support checking for trusted-user.
|
||||
* Try using ssh-ng:// instead if you want to know.
|
||||
|
|
@ -392,12 +345,11 @@ std::optional<TrustedFlag> LegacySSHStore::isTrustedClient()
|
|||
return std::nullopt;
|
||||
}
|
||||
|
||||
|
||||
ref<Store> LegacySSHStore::Config::openStore() const {
|
||||
ref<Store> LegacySSHStore::Config::openStore() const
|
||||
{
|
||||
return make_ref<LegacySSHStore>(ref{shared_from_this()});
|
||||
}
|
||||
|
||||
|
||||
static RegisterStoreImplementation<LegacySSHStore::Config> regLegacySSHStore;
|
||||
|
||||
}
|
||||
} // namespace nix
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue