aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/primops.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-05-22 23:36:29 +0200
committerEelco Dolstra <edolstra@gmail.com>2019-05-22 23:36:29 +0200
commitdf3f5a78d5ab0a1f2dc9d288b271b38a9b8b33b5 (patch)
tree8524ea993ec051f12b879e6b9a10963cfb19b812 /src/libexpr/primops.cc
parent66f1d7ee95ba693a15ae5dc413289fee954f0f04 (diff)
Refactor downloadCached() interface
Diffstat (limited to 'src/libexpr/primops.cc')
-rw-r--r--src/libexpr/primops.cc22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index 55a1bde11..070e72f3a 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -2050,9 +2050,9 @@ static void prim_splitVersion(EvalState & state, const Pos & pos, Value * * args
void fetch(EvalState & state, const Pos & pos, Value * * args, Value & v,
const string & who, bool unpack, const std::string & defaultName)
{
- string url;
- Hash expectedHash;
- string name = defaultName;
+ CachedDownloadRequest request("");
+ request.unpack = unpack;
+ request.name = defaultName;
state.forceValue(*args[0]);
@@ -2063,27 +2063,27 @@ void fetch(EvalState & state, const Pos & pos, Value * * args, Value & v,
for (auto & attr : *args[0]->attrs) {
string n(attr.name);
if (n == "url")
- url = state.forceStringNoCtx(*attr.value, *attr.pos);
+ request.uri = state.forceStringNoCtx(*attr.value, *attr.pos);
else if (n == "sha256")
- expectedHash = Hash(state.forceStringNoCtx(*attr.value, *attr.pos), htSHA256);
+ request.expectedHash = Hash(state.forceStringNoCtx(*attr.value, *attr.pos), htSHA256);
else if (n == "name")
- name = state.forceStringNoCtx(*attr.value, *attr.pos);
+ request.name = state.forceStringNoCtx(*attr.value, *attr.pos);
else
throw EvalError(format("unsupported argument '%1%' to '%2%', at %3%") % attr.name % who % attr.pos);
}
- if (url.empty())
+ if (request.uri.empty())
throw EvalError(format("'url' argument required, at %1%") % pos);
} else
- url = state.forceStringNoCtx(*args[0], pos);
+ request.uri = state.forceStringNoCtx(*args[0], pos);
- state.checkURI(url);
+ state.checkURI(request.uri);
- if (evalSettings.pureEval && !expectedHash)
+ if (evalSettings.pureEval && !request.expectedHash)
throw Error("in pure evaluation mode, '%s' requires a 'sha256' argument", who);
- Path res = getDownloader()->downloadCached(state.store, url, unpack, name, expectedHash).path;
+ Path res = getDownloader()->downloadCached(state.store, request).path;
if (state.allowedPaths)
state.allowedPaths->insert(res);