aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2020-07-21 15:39:47 +0000
committerJohn Ericson <John.Ericson@Obsidian.Systems>2020-07-21 15:39:47 +0000
commit6cce32c8e8b9559f197f6d3e8814796cfc490582 (patch)
tree99b2d8bdf77359a73e2f2c5a4e86231b6285cf13 /src
parent4178f36a1d4005a78a024c60d1f024c6ecccf8e8 (diff)
Change logic for deciding what is a relative path for the local store
The was Eelco's prefered logic, and it looks good to me!
Diffstat (limited to 'src')
-rw-r--r--src/libstore/store-api.cc14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc
index d37e970df..67ce6e66c 100644
--- a/src/libstore/store-api.cc
+++ b/src/libstore/store-api.cc
@@ -914,12 +914,20 @@ ref<Store> openStore(const std::string & uri_,
throw Error("don't know how to open Nix store '%s'", uri);
}
+static bool isNonUriPath(const std::string & spec) {
+ return
+ // is not a URL
+ spec.find("://") == std::string::npos
+ // Has at least one path separator, and so isn't a single word that
+ // might be special like "auto"
+ && spec.find("/") != std::string::npos;
+}
StoreType getStoreType(const std::string & uri, const std::string & stateDir)
{
if (uri == "daemon") {
return tDaemon;
- } else if (uri == "local" || hasPrefix(uri, "/") || hasPrefix(uri, "./")) {
+ } else if (uri == "local" || isNonUriPath(uri)) {
return tLocal;
} else if (uri == "" || uri == "auto") {
if (access(stateDir.c_str(), R_OK | W_OK) == 0)
@@ -943,9 +951,7 @@ static RegisterStoreImplementation regStore([](
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, "./")) {
+ if (isNonUriPath(uri)) {
params2["root"] = absPath(uri);
}
return std::shared_ptr<Store>(std::make_shared<LocalStore>(params2));