diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2020-07-21 19:43:07 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-21 19:43:07 +0200 |
commit | ff314f186e3f91d87af6ad96c0ae3b472494b940 (patch) | |
tree | a4d9dd1afd24fe43203853402baf0d330fbb1b3e /src | |
parent | 0951330680afdec9c6d7deed5047940e5e65ef71 (diff) | |
parent | 6cce32c8e8b9559f197f6d3e8814796cfc490582 (diff) |
Merge pull request #3736 from obsidiansystems/allow-relative-paths-in-store-option
Allow relative paths in --store option
Diffstat (limited to 'src')
-rw-r--r-- | src/libstore/store-api.cc | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index 14661722d..ab21b0bd5 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -967,12 +967,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, "/")) { + } else if (uri == "local" || isNonUriPath(uri)) { return tLocal; } else if (uri == "" || uri == "auto") { if (access(stateDir.c_str(), R_OK | W_OK) == 0) @@ -996,8 +1004,9 @@ 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; + if (isNonUriPath(uri)) { + params2["root"] = absPath(uri); + } return std::shared_ptr<Store>(std::make_shared<LocalStore>(params2)); } default: |