mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2024-11-07 07:26:13 -05:00
daemon: Factorize substituter agent spawning.
* nix/libstore/local-store.hh (class LocalStore)[substituter]: New method. [runningSubstituter]: Turn into a shared_ptr. * nix/libstore/local-store.cc (LocalStore::querySubstitutablePaths): Call 'substituter' instead of using inline code. (LocalStore::querySubstitutablePathInfos): Likewise. (LocalStore::substituter): New method.
This commit is contained in:
parent
79c6614f58
commit
a618a8c620
2 changed files with 17 additions and 17 deletions
|
@ -850,14 +850,7 @@ PathSet LocalStore::querySubstitutablePaths(const PathSet & paths)
|
||||||
|
|
||||||
if (!settings.useSubstitutes || paths.empty()) return res;
|
if (!settings.useSubstitutes || paths.empty()) return res;
|
||||||
|
|
||||||
if (!runningSubstituter) {
|
Agent & run = *substituter();
|
||||||
const Strings args = { "substitute", "--query" };
|
|
||||||
const std::map<string, string> env = { { "_NIX_OPTIONS", settings.pack() } };
|
|
||||||
std::unique_ptr<Agent> fresh(new Agent(settings.guixProgram, args, env));
|
|
||||||
runningSubstituter.swap(fresh);
|
|
||||||
}
|
|
||||||
|
|
||||||
Agent & run = *runningSubstituter;
|
|
||||||
|
|
||||||
string s = "have ";
|
string s = "have ";
|
||||||
foreach (PathSet::const_iterator, j, paths)
|
foreach (PathSet::const_iterator, j, paths)
|
||||||
|
@ -877,18 +870,22 @@ PathSet LocalStore::querySubstitutablePaths(const PathSet & paths)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::shared_ptr<Agent> LocalStore::substituter()
|
||||||
|
{
|
||||||
|
if (!runningSubstituter) {
|
||||||
|
const Strings args = { "substitute", "--query" };
|
||||||
|
const std::map<string, string> env = { { "_NIX_OPTIONS", settings.pack() } };
|
||||||
|
runningSubstituter = std::make_shared<Agent>(settings.guixProgram, args, env);
|
||||||
|
}
|
||||||
|
|
||||||
|
return runningSubstituter;
|
||||||
|
}
|
||||||
|
|
||||||
void LocalStore::querySubstitutablePathInfos(PathSet & paths, SubstitutablePathInfos & infos)
|
void LocalStore::querySubstitutablePathInfos(PathSet & paths, SubstitutablePathInfos & infos)
|
||||||
{
|
{
|
||||||
if (!settings.useSubstitutes) return;
|
if (!settings.useSubstitutes) return;
|
||||||
|
|
||||||
if (!runningSubstituter) {
|
Agent & run = *substituter();
|
||||||
const Strings args = { "substitute", "--query" };
|
|
||||||
const std::map<string, string> env = { { "_NIX_OPTIONS", settings.pack() } };
|
|
||||||
std::unique_ptr<Agent> fresh(new Agent(settings.guixProgram, args, env));
|
|
||||||
runningSubstituter.swap(fresh);
|
|
||||||
}
|
|
||||||
|
|
||||||
Agent & run = *runningSubstituter;
|
|
||||||
|
|
||||||
string s = "info ";
|
string s = "info ";
|
||||||
foreach (PathSet::const_iterator, i, paths)
|
foreach (PathSet::const_iterator, i, paths)
|
||||||
|
|
|
@ -42,7 +42,10 @@ class LocalStore : public StoreAPI
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
/* The currently running substituter or empty. */
|
/* The currently running substituter or empty. */
|
||||||
std::unique_ptr<Agent> runningSubstituter;
|
std::shared_ptr<Agent> runningSubstituter;
|
||||||
|
|
||||||
|
/* Ensure the substituter is running and return it. */
|
||||||
|
std::shared_ptr<Agent> substituter();
|
||||||
|
|
||||||
Path linksDir;
|
Path linksDir;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue