Skip to content

Commit

Permalink
Only register drv outputs when it's safe to do so if ca-drvs aren't e…
Browse files Browse the repository at this point in the history
…nabled

Unless ca drvs are enabled, only allow registering derivation outputs when we
know it's safe to do so, meaning when we can check that the mapping matches
what's defined in the drv file itself
  • Loading branch information
thufschmitt committed Nov 17, 2020
1 parent 4e715de commit dc9e34a
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/libstore/local-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,28 @@ void LocalStore::registerDrvOutput(const DrvOutputId& id, const DrvOutputInfo &

void LocalStore::registerDrvOutput_(State & state, const StorePath & deriver, const string & outputName, const StorePath & output)
{
// Ensure that we don't register a boguous derivation output.
debug("Checking the validiy of the drv output '%s!%s'", printStorePath(deriver), outputName);
if (!isValidPath_(state, deriver))
settings.requireExperimentalFeature("ca-derivations");
else {
// Can't use `readDerivation` here as we already hold the lock on the db
auto matchingDrv = parseDerivation(
*this,
readFile(Store::toRealPath(deriver)),
Derivation::nameFromPath(deriver)
);
auto outputsFromDrv = matchingDrv.outputsAndOptPaths(*this);
auto currentOutputFromDrv = outputsFromDrv.find(outputName);
assert (currentOutputFromDrv != outputsFromDrv.end());
if (!currentOutputFromDrv->second.second.has_value()) {
// Floating-ca or dependent thereof
settings.requireExperimentalFeature("ca-derivations");
} else {
assert (*currentOutputFromDrv->second.second == output);
}
}

retrySQLite<void>([&]() {
state.stmtAddDerivationOutput.use()
(printStorePath(deriver))
Expand Down

0 comments on commit dc9e34a

Please sign in to comment.