forked from lix-project/lix
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;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string uriScheme = "unix://";
|
static std::string_view uriScheme = "unix://";
|
||||||
|
|
||||||
static RegisterStoreImplementation regStore([](
|
static RegisterStoreImplementation regStore([](
|
||||||
const std::string & uri, const Store::Params & params)
|
const std::string & uri, const Store::Params & params)
|
||||||
-> std::shared_ptr<Store>
|
-> std::shared_ptr<Store>
|
||||||
{
|
{
|
||||||
if (std::string(uri, 0, uriScheme.size()) != uriScheme) return 0;
|
if (hasPrefix(uri, uriScheme))
|
||||||
return std::make_shared<UDSRemoteStore>(std::string(uri, uriScheme.size()), params);
|
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)
|
// Specific prefixes are handled by the specific types of store, while here we
|
||||||
{
|
// handle the general cases not covered by the other ones.
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static RegisterStoreImplementation regStore([](
|
static RegisterStoreImplementation regStore([](
|
||||||
const std::string & uri, const Store::Params & params)
|
const std::string & uri, const Store::Params & params)
|
||||||
-> std::shared_ptr<Store>
|
-> std::shared_ptr<Store>
|
||||||
{
|
{
|
||||||
switch (getStoreType(uri, get(params, "state").value_or(settings.nixStateDir))) {
|
auto stateDir = get(params, "state").value_or(settings.nixStateDir);
|
||||||
case tDaemon:
|
if (uri == "" || uri == "auto") {
|
||||||
return std::shared_ptr<Store>(std::make_shared<UDSRemoteStore>(params));
|
if (access(stateDir.c_str(), R_OK | W_OK) == 0)
|
||||||
case tLocal: {
|
return std::make_shared<LocalStore>(params);
|
||||||
Store::Params params2 = params;
|
else if (pathExists(settings.nixDaemonSocketFile))
|
||||||
if (hasPrefix(uri, "/")) {
|
return std::make_shared<UDSRemoteStore>(params);
|
||||||
params2["root"] = uri;
|
else
|
||||||
} else if (hasPrefix(uri, "./")) {
|
return std::make_shared<LocalStore>(params);
|
||||||
params2["root"] = absPath(uri);
|
} else {
|
||||||
}
|
return nullptr;
|
||||||
return std::shared_ptr<Store>(std::make_shared<LocalStore>(params2));
|
}
|
||||||
}
|
|
||||||
default:
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -796,16 +796,6 @@ ref<Store> openStore(const std::string & uri = settings.storeUri.get(),
|
||||||
const Store::Params & extraParams = Store::Params());
|
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
|
/* Return the default substituter stores, defined by the
|
||||||
‘substituters’ option and various legacy options. */
|
‘substituters’ option and various legacy options. */
|
||||||
std::list<ref<Store>> getDefaultSubstituters();
|
std::list<ref<Store>> getDefaultSubstituters();
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "shared.hh"
|
#include "shared.hh"
|
||||||
#include "local-store.hh"
|
#include "local-store.hh"
|
||||||
|
#include "remote-store.hh"
|
||||||
#include "util.hh"
|
#include "util.hh"
|
||||||
#include "serialise.hh"
|
#include "serialise.hh"
|
||||||
#include "archive.hh"
|
#include "archive.hh"
|
||||||
|
@ -277,7 +278,9 @@ static int _main(int argc, char * * argv)
|
||||||
initPlugins();
|
initPlugins();
|
||||||
|
|
||||||
if (stdio) {
|
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
|
// Forward on this connection to the real daemon
|
||||||
auto socketPath = settings.nixDaemonSocketFile;
|
auto socketPath = settings.nixDaemonSocketFile;
|
||||||
auto s = socket(PF_UNIX, SOCK_STREAM, 0);
|
auto s = socket(PF_UNIX, SOCK_STREAM, 0);
|
||||||
|
|
|
@ -49,9 +49,7 @@ struct CmdDoctor : StoreCommand
|
||||||
{
|
{
|
||||||
logger->log("Running checks against store uri: " + store->getUri());
|
logger->log("Running checks against store uri: " + store->getUri());
|
||||||
|
|
||||||
auto type = getStoreType();
|
if (store.dynamic_pointer_cast<LocalFSStore>()) {
|
||||||
|
|
||||||
if (type < tOther) {
|
|
||||||
success &= checkNixInPath();
|
success &= checkNixInPath();
|
||||||
success &= checkProfileRoots(store);
|
success &= checkProfileRoots(store);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue