This commit is contained in:
Eelco Dolstra 2022-03-21 14:34:45 +01:00
parent 41659418cf
commit 7f6fe8ca1d

View file

@ -7,17 +7,17 @@ static void prim_fetchClosure(EvalState & state, const Pos & pos, Value * * args
{
state.forceAttrs(*args[0], pos);
std::optional<StorePath> storePath;
std::optional<std::string> from;
std::optional<std::string> fromStoreUrl;
std::optional<StorePath> fromPath;
for (auto & attr : *args[0]->attrs) {
if (attr.name == "storePath") {
if (attr.name == "fromPath") {
PathSet context;
storePath = state.coerceToStorePath(*attr.pos, *attr.value, context);
fromPath = state.coerceToStorePath(*attr.pos, *attr.value, context);
}
else if (attr.name == "from")
from = state.forceStringNoCtx(*attr.value, *attr.pos);
else if (attr.name == "fromStore")
fromStoreUrl = state.forceStringNoCtx(*attr.value, *attr.pos);
else
throw Error({
@ -26,36 +26,36 @@ static void prim_fetchClosure(EvalState & state, const Pos & pos, Value * * args
});
}
if (!storePath)
if (!fromPath)
throw Error({
.msg = hintfmt("attribute '%s' is missing in call to 'fetchClosure'", "storePath"),
.msg = hintfmt("attribute '%s' is missing in call to 'fetchClosure'", "fromPath"),
.errPos = pos
});
if (!from)
if (!fromStoreUrl)
throw Error({
.msg = hintfmt("attribute '%s' is missing in call to 'fetchClosure'", "from"),
.msg = hintfmt("attribute '%s' is missing in call to 'fetchClosure'", "fromStore"),
.errPos = pos
});
// FIXME: only allow some "trusted" store types (like BinaryCacheStore).
auto srcStore = openStore(*from);
auto fromStore = openStore(*fromStoreUrl);
copyClosure(*srcStore, *state.store, RealisedPath::Set { *storePath });
copyClosure(*fromStore, *state.store, RealisedPath::Set { *fromPath });
/* In pure mode, require a CA path. */
if (evalSettings.pureEval) {
auto info = state.store->queryPathInfo(*storePath);
auto info = state.store->queryPathInfo(*fromPath);
if (!info->isContentAddressed(*state.store))
throw Error({
.msg = hintfmt("in pure mode, 'fetchClosure' requires a content-addressed path, which '%s' isn't",
state.store->printStorePath(*storePath)),
state.store->printStorePath(*fromPath)),
.errPos = pos
});
}
auto storePathS = state.store->printStorePath(*storePath);
v.mkString(storePathS, {storePathS});
auto fromPathS = state.store->printStorePath(*fromPath);
v.mkString(fromPathS, {fromPathS});
}
static RegisterPrimOp primop_fetchClosure({