mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2025-02-17 07:37:18 +02:00
Move isUri() and resolveUri() out of filetransfer.cc
These are purely related to NIX_PATH / -I command line parsing, so put them in libexpr.
This commit is contained in:
parent
85c1959240
commit
432a3a18d2
7 changed files with 27 additions and 31 deletions
|
@ -93,9 +93,9 @@ Bindings * MixEvalArgs::getAutoArgs(EvalState & state)
|
|||
|
||||
SourcePath lookupFileArg(EvalState & state, std::string_view s)
|
||||
{
|
||||
if (isUri(s)) {
|
||||
if (EvalSettings::isPseudoUrl(s)) {
|
||||
auto storePath = fetchers::downloadTarball(
|
||||
state.store, resolveUri(s), "source", false).first;
|
||||
state.store, EvalSettings::resolvePseudoUrl(s), "source", false).first;
|
||||
auto accessor = makeStorePathAccessor(state.store, storePath);
|
||||
state.registerAccessor(accessor);
|
||||
return {accessor, CanonPath::root};
|
||||
|
|
|
@ -405,7 +405,7 @@ static Strings parseNixPath(const std::string & s)
|
|||
}
|
||||
|
||||
if (*p == ':') {
|
||||
if (isUri(std::string(start2, s.end()))) {
|
||||
if (EvalSettings::isPseudoUrl(std::string(start2, s.end()))) {
|
||||
++p;
|
||||
while (p != s.end() && *p != ':') ++p;
|
||||
}
|
||||
|
@ -2563,6 +2563,23 @@ Strings EvalSettings::getDefaultNixPath()
|
|||
return res;
|
||||
}
|
||||
|
||||
bool EvalSettings::isPseudoUrl(std::string_view s)
|
||||
{
|
||||
if (s.compare(0, 8, "channel:") == 0) return true;
|
||||
size_t pos = s.find("://");
|
||||
if (pos == std::string::npos) return false;
|
||||
std::string scheme(s, 0, pos);
|
||||
return scheme == "http" || scheme == "https" || scheme == "file" || scheme == "channel" || scheme == "git" || scheme == "s3" || scheme == "ssh";
|
||||
}
|
||||
|
||||
std::string EvalSettings::resolvePseudoUrl(std::string_view url)
|
||||
{
|
||||
if (hasPrefix(url, "channel:"))
|
||||
return "https://nixos.org/channels/" + std::string(url.substr(8)) + "/nixexprs.tar.xz";
|
||||
else
|
||||
return std::string(url);
|
||||
}
|
||||
|
||||
EvalSettings evalSettings;
|
||||
|
||||
static GlobalConfig::Register rEvalSettings(&evalSettings);
|
||||
|
|
|
@ -602,6 +602,10 @@ struct EvalSettings : Config
|
|||
|
||||
static Strings getDefaultNixPath();
|
||||
|
||||
static bool isPseudoUrl(std::string_view s);
|
||||
|
||||
static std::string resolvePseudoUrl(std::string_view url);
|
||||
|
||||
Setting<bool> enableNativeCode{this, false, "allow-unsafe-native-code-during-evaluation",
|
||||
"Whether builtin functions that allow executing native code should be enabled."};
|
||||
|
||||
|
|
|
@ -776,17 +776,17 @@ SourcePath EvalState::findFile(SearchPath & searchPath, const std::string_view p
|
|||
}
|
||||
|
||||
|
||||
std::optional<SourcePath> EvalState::resolveSearchPathElem(const SearchPathElem & elem, bool initAccessControl)
|
||||
std::optional<SourcePath> EvalState::resolveSearchPathElem(const SearchPathElem & elem, bool initAccessControl)
|
||||
{
|
||||
auto i = searchPathResolved.find(elem.second);
|
||||
if (i != searchPathResolved.end()) return i->second;
|
||||
|
||||
std::optional<SourcePath> res;
|
||||
|
||||
if (isUri(elem.second)) {
|
||||
if (EvalSettings::isPseudoUrl(elem.second)) {
|
||||
try {
|
||||
auto storePath = fetchers::downloadTarball(
|
||||
store, resolveUri(elem.second), "source", false).first;
|
||||
store, EvalSettings::resolvePseudoUrl(elem.second), "source", false).first;
|
||||
auto accessor = makeStorePathAccessor(store, storePath);
|
||||
registerAccessor(accessor);
|
||||
res.emplace(SourcePath {accessor, CanonPath::root});
|
||||
|
|
|
@ -257,8 +257,6 @@ static void fetch(EvalState & state, const PosIdx pos, Value * * args, Value & v
|
|||
} else
|
||||
url = state.forceStringNoCtx(*args[0], pos);
|
||||
|
||||
url = resolveUri(*url);
|
||||
|
||||
state.checkURI(*url);
|
||||
|
||||
if (name == "")
|
||||
|
|
|
@ -33,14 +33,6 @@ FileTransferSettings fileTransferSettings;
|
|||
|
||||
static GlobalConfig::Register rFileTransferSettings(&fileTransferSettings);
|
||||
|
||||
std::string resolveUri(std::string_view uri)
|
||||
{
|
||||
if (uri.compare(0, 8, "channel:") == 0)
|
||||
return "https://nixos.org/channels/" + std::string(uri.substr(8)) + "/nixexprs.tar.xz";
|
||||
else
|
||||
return std::string(uri);
|
||||
}
|
||||
|
||||
struct curlFileTransfer : public FileTransfer
|
||||
{
|
||||
CURLM * curlm = 0;
|
||||
|
@ -874,14 +866,4 @@ FileTransferError::FileTransferError(FileTransfer::Error error, std::optional<st
|
|||
err.msg = hf;
|
||||
}
|
||||
|
||||
bool isUri(std::string_view s)
|
||||
{
|
||||
if (s.compare(0, 8, "channel:") == 0) return true;
|
||||
size_t pos = s.find("://");
|
||||
if (pos == std::string::npos) return false;
|
||||
std::string scheme(s, 0, pos);
|
||||
return scheme == "http" || scheme == "https" || scheme == "file" || scheme == "channel" || scheme == "git" || scheme == "s3" || scheme == "ssh";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -125,9 +125,4 @@ public:
|
|||
FileTransferError(FileTransfer::Error error, std::optional<std::string> response, const Args & ... args);
|
||||
};
|
||||
|
||||
bool isUri(std::string_view s);
|
||||
|
||||
/* Resolve deprecated 'channel:<foo>' URLs. */
|
||||
std::string resolveUri(std::string_view uri);
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue