[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
05/09: daemon: Factorize substituter agent spawning.
From: |
guix-commits |
Subject: |
05/09: daemon: Factorize substituter agent spawning. |
Date: |
Tue, 8 Dec 2020 17:00:14 -0500 (EST) |
civodul pushed a commit to branch master
in repository guix.
commit a618a8c6203d4cf57f12873a86797b8685b11e14
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Tue Dec 1 15:55:57 2020 +0100
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.
---
nix/libstore/local-store.cc | 25 +++++++++++--------------
nix/libstore/local-store.hh | 5 ++++-
2 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/nix/libstore/local-store.cc b/nix/libstore/local-store.cc
index 4219573..c304e2d 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)
diff --git a/nix/libstore/local-store.hh b/nix/libstore/local-store.hh
index 57d15ba..9ba3721 100644
--- a/nix/libstore/local-store.hh
+++ b/nix/libstore/local-store.hh
@@ -42,7 +42,10 @@ class LocalStore : public StoreAPI
{
private:
/* 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;
- branch master updated (20e5658 -> 799f066), guix-commits, 2020/12/08
- 06/09: daemon: Run 'guix substitute --substitute' as an agent., guix-commits, 2020/12/08
- 09/09: import: opam: Adjust test to latest 'opam->guix-package' changes., guix-commits, 2020/12/08
- 04/09: daemon: Use 'Agent' to spawn 'guix substitute --query'., guix-commits, 2020/12/08
- 05/09: daemon: Factorize substituter agent spawning.,
guix-commits <=
- 01/09: database: Remove unnecessary module imports., guix-commits, 2020/12/08
- 08/09: daemon: Raise an error if substituter doesn't send the expected hash., guix-commits, 2020/12/08
- 07/09: substitute: Cache and reuse connections while substituting., guix-commits, 2020/12/08
- 03/09: daemon: 'Agent' constructor takes a list of environment variables., guix-commits, 2020/12/08
- 02/09: gnu: autotools: Add version 2.70., guix-commits, 2020/12/08