forked from lix-project/lix
fetchClosure: Refactor: replace enableRewriting
A single variable is nice and self-contained.
This commit is contained in:
parent
5bdca46117
commit
dc79636007
|
@ -100,14 +100,15 @@ static void runFetchClosureWithInputAddressedPath(EvalState & state, const PosId
|
||||||
state.mkStorePathString(fromPath, v);
|
state.mkStorePathString(fromPath, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef std::optional<StorePath> StorePathOrGap;
|
||||||
|
|
||||||
static void prim_fetchClosure(EvalState & state, const PosIdx pos, Value * * args, Value & v)
|
static void prim_fetchClosure(EvalState & state, const PosIdx pos, Value * * args, Value & v)
|
||||||
{
|
{
|
||||||
state.forceAttrs(*args[0], pos, "while evaluating the argument passed to builtins.fetchClosure");
|
state.forceAttrs(*args[0], pos, "while evaluating the argument passed to builtins.fetchClosure");
|
||||||
|
|
||||||
std::optional<std::string> fromStoreUrl;
|
std::optional<std::string> fromStoreUrl;
|
||||||
std::optional<StorePath> fromPath;
|
std::optional<StorePath> fromPath;
|
||||||
bool enableRewriting = false;
|
std::optional<StorePathOrGap> toPath;
|
||||||
std::optional<StorePath> toPath;
|
|
||||||
std::optional<bool> inputAddressedMaybe;
|
std::optional<bool> inputAddressedMaybe;
|
||||||
|
|
||||||
for (auto & attr : *args[0]->attrs) {
|
for (auto & attr : *args[0]->attrs) {
|
||||||
|
@ -123,8 +124,11 @@ static void prim_fetchClosure(EvalState & state, const PosIdx pos, Value * * arg
|
||||||
|
|
||||||
else if (attrName == "toPath") {
|
else if (attrName == "toPath") {
|
||||||
state.forceValue(*attr.value, attr.pos);
|
state.forceValue(*attr.value, attr.pos);
|
||||||
enableRewriting = true;
|
bool isEmptyString = attr.value->type() == nString && attr.value->string.s == std::string("");
|
||||||
if (attr.value->type() != nString || attr.value->string.s != std::string("")) {
|
if (isEmptyString) {
|
||||||
|
toPath = StorePathOrGap {};
|
||||||
|
}
|
||||||
|
else {
|
||||||
NixStringContext context;
|
NixStringContext context;
|
||||||
toPath = state.coerceToStorePath(attr.pos, *attr.value, context, attrHint());
|
toPath = state.coerceToStorePath(attr.pos, *attr.value, context, attrHint());
|
||||||
}
|
}
|
||||||
|
@ -160,7 +164,6 @@ static void prim_fetchClosure(EvalState & state, const PosIdx pos, Value * * arg
|
||||||
"toPath"),
|
"toPath"),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
});
|
||||||
assert(!enableRewriting);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fromStoreUrl)
|
if (!fromStoreUrl)
|
||||||
|
@ -187,8 +190,8 @@ static void prim_fetchClosure(EvalState & state, const PosIdx pos, Value * * arg
|
||||||
|
|
||||||
auto fromStore = openStore(parsedURL.to_string());
|
auto fromStore = openStore(parsedURL.to_string());
|
||||||
|
|
||||||
if (enableRewriting)
|
if (toPath)
|
||||||
runFetchClosureWithRewrite(state, pos, *fromStore, *fromPath, toPath, v);
|
runFetchClosureWithRewrite(state, pos, *fromStore, *fromPath, *toPath, v);
|
||||||
else if (inputAddressed)
|
else if (inputAddressed)
|
||||||
runFetchClosureWithInputAddressedPath(state, pos, *fromStore, *fromPath, v);
|
runFetchClosureWithInputAddressedPath(state, pos, *fromStore, *fromPath, v);
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue