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.
This commit is contained in:
parent
4178f36a1d
commit
0aa79dcc6f
|
@ -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));
|
||||
});
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "shared.hh"
|
||||
#include "local-store.hh"
|
||||
#include "remote-store.hh"
|
||||
#include "util.hh"
|
||||
#include "serialise.hh"
|
||||
#include "archive.hh"
|
||||
|
@ -277,7 +278,9 @@ static int _main(int argc, char * * argv)
|
|||
initPlugins();
|
||||
|
||||
if (stdio) {
|
||||
if (getStoreType() == tDaemon) {
|
||||
if (openUncachedStore().dynamic_pointer_cast<UDSRemoteStore>()) {
|
||||
// FIXME Use the connection the UDSRemoteStore opened
|
||||
|
||||
// Forward on this connection to the real daemon
|
||||
auto socketPath = settings.nixDaemonSocketFile;
|
||||
auto s = socket(PF_UNIX, SOCK_STREAM, 0);
|
||||
|
|
|
@ -49,9 +49,7 @@ struct CmdDoctor : StoreCommand
|
|||
{
|
||||
logger->log("Running checks against store uri: " + store->getUri());
|
||||
|
||||
auto type = getStoreType();
|
||||
|
||||
if (type < tOther) {
|
||||
if (store.dynamic_pointer_cast<LocalFSStore>()) {
|
||||
success &= checkNixInPath();
|
||||
success &= checkProfileRoots(store);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue