aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/primops.cc
diff options
context:
space:
mode:
authorShea Levy <shea@shealevy.com>2016-08-15 07:37:11 -0400
committerShea Levy <shea@shealevy.com>2016-08-15 07:37:11 -0400
commitd52d391164d9a6fb4a2efec2777e24de5e19b225 (patch)
tree4e1ab818d97a2054abd612b3358b7bb1c18f7102 /src/libexpr/primops.cc
parenteff80419c76eb7d77d3b434a45fb9e18d53d1d19 (diff)
builtins.fetch{url,tarball}: Allow name attribute
Diffstat (limited to 'src/libexpr/primops.cc')
-rw-r--r--src/libexpr/primops.cc11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index c456e9b96..d1d1f8057 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -1682,6 +1682,7 @@ void fetch(EvalState & state, const Pos & pos, Value * * args, Value & v,
{
string url;
Hash expectedHash;
+ string name;
state.forceValue(*args[0]);
@@ -1690,11 +1691,13 @@ void fetch(EvalState & state, const Pos & pos, Value * * args, Value & v,
state.forceAttrs(*args[0], pos);
for (auto & attr : *args[0]->attrs) {
- string name(attr.name);
- if (name == "url")
+ string n(attr.name);
+ if (n == "url")
url = state.forceStringNoCtx(*attr.value, *attr.pos);
- else if (name == "sha256")
+ else if (n == "sha256")
expectedHash = parseHash16or32(htSHA256, state.forceStringNoCtx(*attr.value, *attr.pos));
+ else if (n == "name")
+ name = state.forceStringNoCtx(*attr.value, *attr.pos);
else
throw EvalError(format("unsupported argument ‘%1%’ to ‘%2%’, at %3%") % attr.name % who % attr.pos);
}
@@ -1708,7 +1711,7 @@ void fetch(EvalState & state, const Pos & pos, Value * * args, Value & v,
if (state.restricted && !expectedHash)
throw Error(format("‘%1%’ is not allowed in restricted mode") % who);
- Path res = makeDownloader()->downloadCached(state.store, url, unpack, expectedHash);
+ Path res = makeDownloader()->downloadCached(state.store, url, unpack, name, expectedHash);
mkString(v, res, PathSet({res}));
}