diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2016-11-09T17·57+0100 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2016-11-09T17·57+0100 |
commit | 4b8f1b0ec066a5b994747b1afd050f5f62d857f6 (patch) | |
tree | a946094a9e4a3a56cfe713b01cd7d27104d56b03 /src/libstore/store-api.cc | |
parent | 21c55ab3b54fc2db30ca53c572d24b38331f508c (diff) | |
parent | b99c6e0e2959e90ddda14d8b318e4c7b1a508674 (diff) |
Merge branch 'ssh-store' of https://github.com/shlevy/nix
Diffstat (limited to 'src/libstore/store-api.cc')
-rw-r--r-- | src/libstore/store-api.cc | 47 |
1 files changed, 24 insertions, 23 deletions
diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index f365406cb961..f7f6c9696688 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -606,7 +606,7 @@ namespace nix { RegisterStoreImplementation::Implementations * RegisterStoreImplementation::implementations = 0; -ref<Store> openStoreAt(const std::string & uri_) +ref<Store> openStore(const std::string & uri_) { auto uri(uri_); Store::Params params; @@ -629,9 +629,22 @@ ref<Store> openStoreAt(const std::string & uri_) } -ref<Store> openStore() +StoreType getStoreType(const std::string & uri, const std::string & stateDir) { - return openStoreAt(getEnv("NIX_REMOTE")); + if (uri == "daemon") { + return tDaemon; + } else if (uri == "local") { + return tLocal; + } else if (uri == "") { + 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; + } } @@ -639,26 +652,14 @@ static RegisterStoreImplementation regStore([]( const std::string & uri, const Store::Params & params) -> std::shared_ptr<Store> { - 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 (access(stateDir.c_str(), R_OK | W_OK) == 0) - mode = mLocal; - else if (pathExists(settings.nixDaemonSocketFile)) - mode = mDaemon; - else - mode = mLocal; + switch (getStoreType(uri, get(params, "state", settings.nixStateDir))) { + case tDaemon: + return std::shared_ptr<Store>(std::make_shared<UDSRemoteStore>(params)); + case tLocal: + return std::shared_ptr<Store>(std::make_shared<LocalStore>(params)); + default: + return nullptr; } - - return mode == mDaemon - ? std::shared_ptr<Store>(std::make_shared<RemoteStore>(params)) - : std::shared_ptr<Store>(std::make_shared<LocalStore>(params)); }); @@ -679,7 +680,7 @@ std::list<ref<Store>> getDefaultSubstituters() auto addStore = [&](const std::string & uri) { if (done.count(uri)) return; done.insert(uri); - state->stores.push_back(openStoreAt(uri)); + state->stores.push_back(openStore(uri)); }; for (auto uri : settings.get("substituters", Strings())) |