aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/local-binary-cache-store.cc
diff options
context:
space:
mode:
authorregnat <rg@regnat.ovh>2020-09-08 14:50:23 +0200
committerregnat <rg@regnat.ovh>2020-09-16 13:53:08 +0200
commit7d5bdf8b5679cc7b2b9b4d9caf5af9ca52211336 (patch)
tree42c5061563eaa66a36a30380ccbac721e8c7423e /src/libstore/local-binary-cache-store.cc
parent609a6d6d9f1a8689c2336301a2e4db01ad20037c (diff)
Make the store plugins more introspectable
Directly register the store classes rather than a function to build an instance of them. This gives the possibility to introspect static members of the class or choose different ways of instantiating them.
Diffstat (limited to 'src/libstore/local-binary-cache-store.cc')
-rw-r--r--src/libstore/local-binary-cache-store.cc23
1 files changed, 12 insertions, 11 deletions
diff --git a/src/libstore/local-binary-cache-store.cc b/src/libstore/local-binary-cache-store.cc
index 87d8334d7..752838d3f 100644
--- a/src/libstore/local-binary-cache-store.cc
+++ b/src/libstore/local-binary-cache-store.cc
@@ -13,7 +13,8 @@ private:
public:
LocalBinaryCacheStore(
- const Params & params, const Path & binaryCacheDir)
+ const Path & binaryCacheDir,
+ const Params & params)
: BinaryCacheStore(params)
, binaryCacheDir(binaryCacheDir)
{
@@ -26,6 +27,8 @@ public:
return "file://" + binaryCacheDir;
}
+ static std::vector<std::string> uriPrefixes();
+
protected:
bool fileExists(const std::string & path) override;
@@ -85,16 +88,14 @@ bool LocalBinaryCacheStore::fileExists(const std::string & path)
return pathExists(binaryCacheDir + "/" + path);
}
-static RegisterStoreImplementation regStore([](
- const std::string & uri, const Store::Params & params)
- -> std::shared_ptr<Store>
+std::vector<std::string> LocalBinaryCacheStore::uriPrefixes()
{
- if (getEnv("_NIX_FORCE_HTTP_BINARY_CACHE_STORE") == "1" ||
- std::string(uri, 0, 7) != "file://")
- return 0;
- auto store = std::make_shared<LocalBinaryCacheStore>(params, std::string(uri, 7));
- store->init();
- return store;
-});
+ if (getEnv("_NIX_FORCE_HTTP_BINARY_CACHE_STORE") == "1")
+ return {};
+ else
+ return {"file"};
+}
+
+[[maybe_unused]] static RegisterStoreImplementation<LocalBinaryCacheStore> regStore();
}