diff options
author | Ludovic Courtès <ludo@gnu.org> | 2020-12-01 15:55:57 +0100 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2020-12-08 22:30:08 +0100 |
commit | a618a8c6203d4cf57f12873a86797b8685b11e14 (patch) | |
tree | b7b6eec5c5f387ccbaa8dfcd0859fa50047e6c8d /nix/libstore/local-store.cc | |
parent | 79c6614f58a57b985daf8940766319e440311db0 (diff) | |
download | guix-a618a8c6203d4cf57f12873a86797b8685b11e14.tar.gz |
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.
Diffstat (limited to 'nix/libstore/local-store.cc')
-rw-r--r-- | nix/libstore/local-store.cc | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/nix/libstore/local-store.cc b/nix/libstore/local-store.cc index 4219573a56..c304e2ddd1 100644 --- a/nix/libstore/local-store.cc +++ b/nix/libstore/local-store.cc @@ -850,14 +850,7 @@ PathSet LocalStore::querySubstitutablePaths(const PathSet & paths) if (!settings.useSubstitutes || paths.empty()) return res; - if (!runningSubstituter) { - 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; + Agent & run = *substituter(); string s = "have "; foreach (PathSet::const_iterator, j, paths) @@ -877,18 +870,22 @@ PathSet LocalStore::querySubstitutablePaths(const PathSet & paths) } -void LocalStore::querySubstitutablePathInfos(PathSet & paths, SubstitutablePathInfos & infos) +std::shared_ptr<Agent> LocalStore::substituter() { - if (!settings.useSubstitutes) return; - if (!runningSubstituter) { 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); + runningSubstituter = std::make_shared<Agent>(settings.guixProgram, args, env); } - Agent & run = *runningSubstituter; + return runningSubstituter; +} + +void LocalStore::querySubstitutablePathInfos(PathSet & paths, SubstitutablePathInfos & infos) +{ + if (!settings.useSubstitutes) return; + + Agent & run = *substituter(); string s = "info "; foreach (PathSet::const_iterator, i, paths) |