aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorregnat <rg@regnat.ovh>2020-09-09 11:29:17 +0200
committerregnat <rg@regnat.ovh>2020-09-16 13:53:08 +0200
commit3b57181f8ed94cfa149ad4319ba96d41c5fbc30e (patch)
tree76482159f03ceb75eab14c3f4a682eae22d6fe14 /src
parentfa32560169ffa55b9e0b6d5f04c3792acf0c544a (diff)
Separate the instantiation and initialisation of the stores
Add a new `init()` method to the `Store` class that is supposed to handle all the effectful initialisation needed to set-up the store. The constructor should remain side-effect free and just initialize the c++ data structure. The goal behind that is that we can create “dummy” instances of each store to query static properties about it (the parameters it accepts for example)
Diffstat (limited to 'src')
-rw-r--r--src/libstore/binary-cache-store.hh2
-rw-r--r--src/libstore/dummy-store.cc4
-rw-r--r--src/libstore/http-binary-cache-store.cc6
-rw-r--r--src/libstore/legacy-ssh-store.cc3
-rw-r--r--src/libstore/local-binary-cache-store.cc6
-rw-r--r--src/libstore/s3-binary-cache-store.cc3
-rw-r--r--src/libstore/ssh-store.cc6
-rw-r--r--src/libstore/store-api.cc3
-rw-r--r--src/libstore/store-api.hh16
9 files changed, 43 insertions, 6 deletions
diff --git a/src/libstore/binary-cache-store.hh b/src/libstore/binary-cache-store.hh
index 9bcdf5901..881398ea2 100644
--- a/src/libstore/binary-cache-store.hh
+++ b/src/libstore/binary-cache-store.hh
@@ -58,7 +58,7 @@ public:
public:
- virtual void init();
+ virtual void init() override;
private:
diff --git a/src/libstore/dummy-store.cc b/src/libstore/dummy-store.cc
index dd1880877..52086445e 100644
--- a/src/libstore/dummy-store.cc
+++ b/src/libstore/dummy-store.cc
@@ -5,6 +5,10 @@ namespace nix {
struct DummyStore : public Store
{
DummyStore(const std::string uri, const Params & params)
+ : DummyStore(params)
+ { }
+
+ DummyStore(const Params & params)
: Store(params)
{ }
diff --git a/src/libstore/http-binary-cache-store.cc b/src/libstore/http-binary-cache-store.cc
index c1abe35cb..e76bac6e2 100644
--- a/src/libstore/http-binary-cache-store.cc
+++ b/src/libstore/http-binary-cache-store.cc
@@ -24,6 +24,12 @@ private:
public:
HttpBinaryCacheStore(
+ const Params & params)
+ : HttpBinaryCacheStore("dummy", params)
+ {
+ }
+
+ HttpBinaryCacheStore(
const Path & _cacheUri,
const Params & params)
: BinaryCacheStore(params)
diff --git a/src/libstore/legacy-ssh-store.cc b/src/libstore/legacy-ssh-store.cc
index 552b4b176..777ba7520 100644
--- a/src/libstore/legacy-ssh-store.cc
+++ b/src/libstore/legacy-ssh-store.cc
@@ -37,6 +37,9 @@ struct LegacySSHStore : public Store
static std::vector<std::string> uriPrefixes() { return {"ssh"}; }
+ LegacySSHStore(const Params & params)
+ : LegacySSHStore("dummy", params)
+ {}
LegacySSHStore(const string & host, const Params & params)
: Store(params)
diff --git a/src/libstore/local-binary-cache-store.cc b/src/libstore/local-binary-cache-store.cc
index 808a1338f..bcd23eb82 100644
--- a/src/libstore/local-binary-cache-store.cc
+++ b/src/libstore/local-binary-cache-store.cc
@@ -13,6 +13,12 @@ private:
public:
LocalBinaryCacheStore(
+ const Params & params)
+ : LocalBinaryCacheStore("dummy", params)
+ {
+ }
+
+ LocalBinaryCacheStore(
const Path & binaryCacheDir,
const Params & params)
: BinaryCacheStore(params)
diff --git a/src/libstore/s3-binary-cache-store.cc b/src/libstore/s3-binary-cache-store.cc
index f426b43a9..ab27f203f 100644
--- a/src/libstore/s3-binary-cache-store.cc
+++ b/src/libstore/s3-binary-cache-store.cc
@@ -192,6 +192,9 @@ struct S3BinaryCacheStoreImpl : public S3BinaryCacheStore
S3Helper s3Helper;
+ S3BinaryCacheStoreImpl(const Params & params)
+ : S3BinaryCacheStoreImpl("dummy-bucket", params) {}
+
S3BinaryCacheStoreImpl(
const std::string & bucketName,
const Params & params)
diff --git a/src/libstore/ssh-store.cc b/src/libstore/ssh-store.cc
index 8177a95b0..85ddce8be 100644
--- a/src/libstore/ssh-store.cc
+++ b/src/libstore/ssh-store.cc
@@ -17,6 +17,12 @@ public:
const Setting<Path> remoteProgram{(Store*) this, "nix-daemon", "remote-program", "path to the nix-daemon executable on the remote system"};
const Setting<std::string> remoteStore{(Store*) this, "", "remote-store", "URI of the store on the remote system"};
+ SSHStore(
+ const Params & params)
+ : SSHStore("dummy", params)
+ {
+ }
+
SSHStore(const std::string & host, const Params & params)
: Store(params)
, RemoteStore(params)
diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc
index 0f321b434..e14f361bd 100644
--- a/src/libstore/store-api.cc
+++ b/src/libstore/store-api.cc
@@ -1094,8 +1094,9 @@ ref<Store> openStore(const std::string & uri_,
}
for (auto implem : *Implementations::registered) {
- auto store = implem.open(uri, params);
+ auto store = implem.create(uri, params);
if (store) {
+ store->init();
store->warnUnknownSettings();
return ref<Store>(store);
}
diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh
index 61080978e..6e081da41 100644
--- a/src/libstore/store-api.hh
+++ b/src/libstore/store-api.hh
@@ -200,9 +200,12 @@ protected:
Store(const Params & params);
- std::shared_ptr<Config> getConfig();
-
public:
+ /**
+ * Perform any necessary effectful operation to make the store up and
+ * running
+ */
+ virtual void init() {};
virtual ~Store() { }
@@ -749,7 +752,8 @@ std::list<ref<Store>> getDefaultSubstituters();
struct StoreFactory
{
- std::function<std::shared_ptr<Store> (const std::string & uri, const Store::Params & params)> open;
+ std::function<std::shared_ptr<Store> (const std::string & uri, const Store::Params & params)> create;
+ std::function<std::shared_ptr<Store> (const Store::Params & params)> createDummy;
};
struct Implementations
{
@@ -760,10 +764,14 @@ struct Implementations
{
if (!registered) registered = new std::vector<StoreFactory>();
StoreFactory factory{
- .open =
+ .create =
([](const std::string & uri, const Store::Params & params)
-> std::shared_ptr<Store>
{ return std::make_shared<T>(uri, params); }),
+ .createDummy =
+ ([](const Store::Params & params)
+ -> std::shared_ptr<Store>
+ { return std::make_shared<T>(params); })
};
registered->push_back(factory);
}