diff options
Diffstat (limited to 'src/libstore')
-rw-r--r-- | src/libstore/local-store.cc | 22 | ||||
-rw-r--r-- | src/libstore/remote-store.cc | 10 | ||||
-rw-r--r-- | src/libstore/store-api.cc | 53 | ||||
-rw-r--r-- | src/libstore/store-api.hh | 10 |
4 files changed, 42 insertions, 53 deletions
diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index bccd77b68..990810b0e 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -1529,5 +1529,27 @@ void LocalStore::createUser(const std::string & userName, uid_t userId) } } +static bool isNonUriPath(const std::string & spec) { + return + // is not a URL + spec.find("://") == std::string::npos + // Has at least one path separator, and so isn't a single word that + // might be special like "auto" + && spec.find("/") != std::string::npos; +} + +static RegisterStoreImplementation regStore([]( + const std::string & uri, const Store::Params & params) + -> std::shared_ptr<Store> +{ + Store::Params params2 = params; + if (uri == "local") { + } else if (isNonUriPath(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 8dcc1d710..553069b89 100644 --- a/src/libstore/remote-store.cc +++ b/src/libstore/remote-store.cc @@ -941,14 +941,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 539a66c98..6fd0fdfda 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -1015,51 +1015,24 @@ ref<Store> openStore(const std::string & uri_, throw Error("don't know how to open Nix store '%s'", uri); } -static bool isNonUriPath(const std::string & spec) { - return - // is not a URL - spec.find("://") == std::string::npos - // Has at least one path separator, and so isn't a single word that - // might be special like "auto" - && spec.find("/") != std::string::npos; -} - -StoreType getStoreType(const std::string & uri, const std::string & stateDir) -{ - if (uri == "daemon") { - return tDaemon; - } else if (uri == "local" || isNonUriPath(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 (isNonUriPath(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 128682e7a..1680065f3 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -723,16 +723,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(); |