Enable the --store option to take relative paths

In nix commands which accept --store options, we can now specify a
relative path, which will be canonicalized.
This commit is contained in:
Carlo Nucera 2020-06-23 11:12:01 -04:00
parent 015e1c2131
commit e197bc6229

View file

@ -864,7 +864,7 @@ StoreType getStoreType(const std::string & uri, const std::string & stateDir)
{
if (uri == "daemon") {
return tDaemon;
} else if (uri == "local" || hasPrefix(uri, "/")) {
} 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)
@ -888,8 +888,11 @@ static RegisterStoreImplementation regStore([](
return std::shared_ptr<Store>(std::make_shared<UDSRemoteStore>(params));
case tLocal: {
Store::Params params2 = params;
if (hasPrefix(uri, "/"))
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: