diff options
author | Shea Levy <shea@shealevy.com> | 2016-09-02T10·39-0400 |
---|---|---|
committer | Shea Levy <shea@shealevy.com> | 2016-09-02T10·39-0400 |
commit | 53b27ddce22869430e2ab0932c32d8e3c3844564 (patch) | |
tree | 35dc94e0137edd8cd73a31ae7a387d3d7df08b3e /src/libstore/store-api.cc | |
parent | a91954f0c658e90b08f7f6e371305281e4d7d329 (diff) |
Factor a function to get the store type from a URI out of the main RegisterStoreImplementation
Diffstat (limited to 'src/libstore/store-api.cc')
-rw-r--r-- | src/libstore/store-api.cc | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index 75456ab8c8af..604f0dac8989 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -529,30 +529,37 @@ ref<Store> openStore(const std::string & uri_) } -static RegisterStoreImplementation regStore([]( - const std::string & uri, const Store::Params & params) - -> std::shared_ptr<Store> +StoreType getStoreType(const std::string & uri, const std::string & stateDir) { - enum { mDaemon, mLocal, mAuto } mode; - - if (uri == "daemon") mode = mDaemon; - else if (uri == "local") mode = mLocal; - else if (uri == "") mode = mAuto; - else return 0; - - if (mode == mAuto) { - auto stateDir = get(params, "state", settings.nixStateDir); + if (uri == "daemon") { + return tDaemon; + } else if (uri == "local") { + return tLocal; + } else if (uri == "") { if (access(stateDir.c_str(), R_OK | W_OK) == 0) - mode = mLocal; + return tLocal; else if (pathExists(settings.nixDaemonSocketFile)) - mode = mDaemon; + return tDaemon; else - mode = mLocal; + return tLocal; + } else { + return tOther; } +} - return mode == mDaemon - ? std::shared_ptr<Store>(std::make_shared<RemoteStore>(params)) - : std::shared_ptr<Store>(std::make_shared<LocalStore>(params)); + +static RegisterStoreImplementation regStore([]( + const std::string & uri, const Store::Params & params) + -> std::shared_ptr<Store> +{ + switch (getStoreType(uri, get(params, "state", settings.nixStateDir))) { + case tDaemon: + return std::shared_ptr<Store>(std::make_shared<RemoteStore>(params)); + case tLocal: + return std::shared_ptr<Store>(std::make_shared<LocalStore>(params)); + default: + return nullptr; + } }); |