Skip to content

Commit

Permalink
Add StoreURI::render
Browse files Browse the repository at this point in the history
This will be needed for the next step.
  • Loading branch information
Ericson2314 committed May 21, 2024
1 parent 68357e2 commit 024fbe7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/libstore/store-reference.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "url.hh"
#include "store-reference.hh"
#include "file-system.hh"
#include "util.hh"

namespace nix {

Expand All @@ -17,6 +18,26 @@ static bool isNonUriPath(const std::string & spec)
&& spec.find("/") != std::string::npos;
}

std::string StoreReference::render() const
{
std::string res;

std::visit(
overloaded{
[&](const StoreReference::Auto &) { res = "auto"; },
[&](const StoreReference::Specified & g) {
res = g.scheme;
res += "://";
res += g.authority;
},
},
variant);

res += encodeQuery(params);

return res;
}

StoreReference StoreReference::parse(const std::string & uri, const StoreReference::Params & extraParams)
{
auto params = extraParams;
Expand Down
2 changes: 2 additions & 0 deletions src/libstore/store-reference.hh
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ struct StoreReference

auto operator<=>(const StoreReference & rhs) const = default;

std::string render() const;

static StoreReference parse(const std::string & uri, const Params & extraParams = Params{});
};

Expand Down
2 changes: 2 additions & 0 deletions src/libutil/url.hh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ std::string percentEncode(std::string_view s, std::string_view keep="");

std::map<std::string, std::string> decodeQuery(const std::string & query);

std::string encodeQuery(const std::map<std::string, std::string> & query);

ParsedURL parseURL(const std::string & url);

/**
Expand Down

0 comments on commit 024fbe7

Please sign in to comment.