mirror of
https://github.com/NixOS/nix
synced 2025-07-07 06:01:48 +02:00
builtins.fetch{url,tarball}: Allow name attribute
(cherry picked from commit d52d391164
)
This commit is contained in:
parent
66151dc154
commit
7bb4d028a8
3 changed files with 12 additions and 8 deletions
|
@ -1657,6 +1657,7 @@ void fetch(EvalState & state, const Pos & pos, Value * * args, Value & v,
|
||||||
if (state.restricted) throw Error(format("‘%1%’ is not allowed in restricted mode") % who);
|
if (state.restricted) throw Error(format("‘%1%’ is not allowed in restricted mode") % who);
|
||||||
|
|
||||||
string url;
|
string url;
|
||||||
|
string name;
|
||||||
|
|
||||||
state.forceValue(*args[0]);
|
state.forceValue(*args[0]);
|
||||||
|
|
||||||
|
@ -1665,9 +1666,11 @@ void fetch(EvalState & state, const Pos & pos, Value * * args, Value & v,
|
||||||
state.forceAttrs(*args[0], pos);
|
state.forceAttrs(*args[0], pos);
|
||||||
|
|
||||||
for (auto & attr : *args[0]->attrs) {
|
for (auto & attr : *args[0]->attrs) {
|
||||||
string name(attr.name);
|
string n(attr.name);
|
||||||
if (name == "url")
|
if (n == "url")
|
||||||
url = state.forceStringNoCtx(*attr.value, *attr.pos);
|
url = state.forceStringNoCtx(*attr.value, *attr.pos);
|
||||||
|
else if (n == "name")
|
||||||
|
name = state.forceStringNoCtx(*attr.value, *attr.pos);
|
||||||
else
|
else
|
||||||
throw EvalError(format("unsupported argument ‘%1%’ to ‘%2%’, at %3%") % attr.name % who % attr.pos);
|
throw EvalError(format("unsupported argument ‘%1%’ to ‘%2%’, at %3%") % attr.name % who % attr.pos);
|
||||||
}
|
}
|
||||||
|
@ -1678,7 +1681,7 @@ void fetch(EvalState & state, const Pos & pos, Value * * args, Value & v,
|
||||||
} else
|
} else
|
||||||
url = state.forceStringNoCtx(*args[0], pos);
|
url = state.forceStringNoCtx(*args[0], pos);
|
||||||
|
|
||||||
Path res = downloadFileCached(url, unpack);
|
Path res = downloadFileCached(url, unpack, name);
|
||||||
mkString(v, res, PathSet({res}));
|
mkString(v, res, PathSet({res}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -188,7 +188,7 @@ DownloadResult downloadFile(string url, const DownloadOptions & options)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Path downloadFileCached(const string & url, bool unpack)
|
Path downloadFileCached(const string & url, bool unpack, string name)
|
||||||
{
|
{
|
||||||
Path cacheDir = getEnv("XDG_CACHE_HOME", getEnv("HOME", "") + "/.cache") + "/nix/tarballs";
|
Path cacheDir = getEnv("XDG_CACHE_HOME", getEnv("HOME", "") + "/.cache") + "/nix/tarballs";
|
||||||
createDirs(cacheDir);
|
createDirs(cacheDir);
|
||||||
|
@ -223,9 +223,10 @@ Path downloadFileCached(const string & url, bool unpack)
|
||||||
storePath = "";
|
storePath = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
string name;
|
if (name == "") {
|
||||||
auto p = url.rfind('/');
|
auto p = url.rfind('/');
|
||||||
if (p != string::npos) name = string(url, p + 1);
|
if (p != string::npos) name = string(url, p + 1);
|
||||||
|
}
|
||||||
|
|
||||||
if (!skip) {
|
if (!skip) {
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ struct DownloadResult
|
||||||
|
|
||||||
DownloadResult downloadFile(string url, const DownloadOptions & options);
|
DownloadResult downloadFile(string url, const DownloadOptions & options);
|
||||||
|
|
||||||
Path downloadFileCached(const string & url, bool unpack);
|
Path downloadFileCached(const string & url, bool unpack, string name = "");
|
||||||
|
|
||||||
MakeError(DownloadError, Error)
|
MakeError(DownloadError, Error)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue