fetchClosure: Skip makeContentAddressed() if toPath is already valid

This commit is contained in:
Eelco Dolstra 2022-03-22 22:01:20 +01:00
parent 5acaf13d35
commit 7ffda0af6e

View file

@ -54,26 +54,28 @@ static void prim_fetchClosure(EvalState & state, const Pos & pos, Value * * args
auto fromStore = openStore(*fromStoreUrl); auto fromStore = openStore(*fromStoreUrl);
if (toCA) { if (toCA) {
auto remappings = makeContentAddressed(*fromStore, *state.store, { *fromPath }); if (!toPath || !state.store->isValidPath(*toPath)) {
auto i = remappings.find(*fromPath); auto remappings = makeContentAddressed(*fromStore, *state.store, { *fromPath });
assert(i != remappings.end()); auto i = remappings.find(*fromPath);
if (toPath && *toPath != i->second) assert(i != remappings.end());
throw Error({ if (toPath && *toPath != i->second)
.msg = hintfmt("rewriting '%s' to content-addressed form yielded '%s', while '%s' was expected", throw Error({
state.store->printStorePath(*fromPath), .msg = hintfmt("rewriting '%s' to content-addressed form yielded '%s', while '%s' was expected",
state.store->printStorePath(i->second), state.store->printStorePath(*fromPath),
state.store->printStorePath(*toPath)), state.store->printStorePath(i->second),
.errPos = pos state.store->printStorePath(*toPath)),
}); .errPos = pos
if (!toPath) });
throw Error({ if (!toPath)
.msg = hintfmt( throw Error({
"rewriting '%s' to content-addressed form yielded '%s'; " .msg = hintfmt(
"please set this in the 'toPath' attribute passed to 'fetchClosure'", "rewriting '%s' to content-addressed form yielded '%s'; "
state.store->printStorePath(*fromPath), "please set this in the 'toPath' attribute passed to 'fetchClosure'",
state.store->printStorePath(i->second)), state.store->printStorePath(*fromPath),
.errPos = pos state.store->printStorePath(i->second)),
}); .errPos = pos
});
}
} else { } else {
copyClosure(*fromStore, *state.store, RealisedPath::Set { *fromPath }); copyClosure(*fromStore, *state.store, RealisedPath::Set { *fromPath });
toPath = fromPath; toPath = fromPath;