mirror of
https://github.com/NixOS/nix
synced 2025-06-27 08:31:16 +02:00
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)
This commit is contained in:
parent
fa32560169
commit
3b57181f8e
9 changed files with 43 additions and 6 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue