aboutsummaryrefslogtreecommitdiff
path: root/src/libstore
diff options
context:
space:
mode:
authorCarlo Nucera <carlo.nucera@protonmail.com>2020-07-17 17:24:02 -0400
committerCarlo Nucera <carlo.nucera@protonmail.com>2020-07-17 17:24:02 -0400
commit0aa79dcc6f4e67891cdd9500ae4ce85e4189a951 (patch)
treeba77166ca10df3569dc3f20c78a78543424fd913 /src/libstore
parent4178f36a1d4005a78a024c60d1f024c6ecccf8e8 (diff)
Remove StoreType abstraction and delegate regStore
to each Store implementation. The generic regStore implementation will only be for the ambiguous shorthands, like "" and "auto". This also could get us close to simplifying the daemon command.
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/local-store.cc16
-rw-r--r--src/libstore/remote-store.cc10
-rw-r--r--src/libstore/store-api.cc47
-rw-r--r--src/libstore/store-api.hh10
4 files changed, 36 insertions, 47 deletions
diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc
index d49d00d6d..9752f3c5f 100644
--- a/src/libstore/local-store.cc
+++ b/src/libstore/local-store.cc
@@ -1580,4 +1580,20 @@ void LocalStore::createUser(const std::string & userName, uid_t userId)
}
+static RegisterStoreImplementation regStore([](
+ const std::string & uri, const Store::Params & params)
+ -> std::shared_ptr<Store>
+{
+ Store::Params params2 = params;
+ if (uri == "local") {
+ } else if (hasPrefix(uri, "/")) {
+ params2["root"] = uri;
+ } else if (hasPrefix(uri, "./")) {
+ params2["root"] = absPath(uri);
+ } else {
+ return nullptr;
+ }
+ return std::shared_ptr<Store>(std::make_shared<LocalStore>(params2));
+});
+
}
diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc
index 9af4364b7..a9fbf9f82 100644
--- a/src/libstore/remote-store.cc
+++ b/src/libstore/remote-store.cc
@@ -843,14 +843,18 @@ std::exception_ptr RemoteStore::Connection::processStderr(Sink * sink, Source *
return nullptr;
}
-static std::string uriScheme = "unix://";
+static std::string_view uriScheme = "unix://";
static RegisterStoreImplementation regStore([](
const std::string & uri, const Store::Params & params)
-> std::shared_ptr<Store>
{
- if (std::string(uri, 0, uriScheme.size()) != uriScheme) return 0;
- return std::make_shared<UDSRemoteStore>(std::string(uri, uriScheme.size()), params);
+ if (hasPrefix(uri, uriScheme))
+ return std::make_shared<UDSRemoteStore>(std::string(uri, uriScheme.size()), params);
+ else if (uri == "daemon")
+ return std::make_shared<UDSRemoteStore>(params);
+ else
+ return nullptr;
});
}
diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc
index d37e970df..7a380f127 100644
--- a/src/libstore/store-api.cc
+++ b/src/libstore/store-api.cc
@@ -915,44 +915,23 @@ ref<Store> openStore(const std::string & uri_,
}
-StoreType getStoreType(const std::string & uri, const std::string & stateDir)
-{
- if (uri == "daemon") {
- return tDaemon;
- } else if (uri == "local" || hasPrefix(uri, "/") || hasPrefix(uri, "./")) {
- return tLocal;
- } else if (uri == "" || uri == "auto") {
- if (access(stateDir.c_str(), R_OK | W_OK) == 0)
- return tLocal;
- else if (pathExists(settings.nixDaemonSocketFile))
- return tDaemon;
- else
- return tLocal;
- } else {
- return tOther;
- }
-}
-
-
+// Specific prefixes are handled by the specific types of store, while here we
+// handle the general cases not covered by the other ones.
static RegisterStoreImplementation regStore([](
const std::string & uri, const Store::Params & params)
-> std::shared_ptr<Store>
{
- switch (getStoreType(uri, get(params, "state").value_or(settings.nixStateDir))) {
- case tDaemon:
- return std::shared_ptr<Store>(std::make_shared<UDSRemoteStore>(params));
- case tLocal: {
- Store::Params params2 = params;
- if (hasPrefix(uri, "/")) {
- params2["root"] = uri;
- } else if (hasPrefix(uri, "./")) {
- params2["root"] = absPath(uri);
- }
- return std::shared_ptr<Store>(std::make_shared<LocalStore>(params2));
- }
- default:
- return nullptr;
- }
+ auto stateDir = get(params, "state").value_or(settings.nixStateDir);
+ if (uri == "" || uri == "auto") {
+ if (access(stateDir.c_str(), R_OK | W_OK) == 0)
+ return std::make_shared<LocalStore>(params);
+ else if (pathExists(settings.nixDaemonSocketFile))
+ return std::make_shared<UDSRemoteStore>(params);
+ else
+ return std::make_shared<LocalStore>(params);
+ } else {
+ return nullptr;
+ }
});
diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh
index a4be0411e..c38290add 100644
--- a/src/libstore/store-api.hh
+++ b/src/libstore/store-api.hh
@@ -796,16 +796,6 @@ ref<Store> openStore(const std::string & uri = settings.storeUri.get(),
const Store::Params & extraParams = Store::Params());
-enum StoreType {
- tDaemon,
- tLocal,
- tOther
-};
-
-
-StoreType getStoreType(const std::string & uri = settings.storeUri.get(),
- const std::string & stateDir = settings.nixStateDir);
-
/* Return the default substituter stores, defined by the
‘substituters’ option and various legacy options. */
std::list<ref<Store>> getDefaultSubstituters();