Skip to content

Commit 90db12c

Browse files
committed
eval-cache: Add derivation result as temproot
Closes the window where the derivation could be garbage collected after we checked isValidPath.
1 parent 0187919 commit 90db12c

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

src/libexpr/eval-cache.cc

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -707,13 +707,16 @@ StorePath AttrCursor::forceDerivation()
707707
auto aDrvPath = getAttr(root->state.s.drvPath);
708708
auto drvPath = root->state.store->parseStorePath(aDrvPath->getString());
709709
drvPath.requireDerivation();
710-
if (!root->state.store->isValidPath(drvPath) && !settings.readOnlyMode) {
711-
/* The eval cache contains 'drvPath', but the actual path has
712-
been garbage-collected. So force it to be regenerated. */
713-
aDrvPath->forceValue();
714-
if (!root->state.store->isValidPath(drvPath))
715-
throw Error(
716-
"don't know how to recreate store derivation '%s'!", root->state.store->printStorePath(drvPath));
710+
if (!settings.readOnlyMode) {
711+
root->state.store->addTempRoot(drvPath);
712+
if (!root->state.store->isValidPath(drvPath)) {
713+
/* The eval cache contains 'drvPath', but the actual path has
714+
been garbage-collected. So force it to be regenerated. */
715+
aDrvPath->forceValue();
716+
if (!root->state.store->isValidPath(drvPath))
717+
throw Error(
718+
"don't know how to recreate store derivation '%s'!", root->state.store->printStorePath(drvPath));
719+
}
717720
}
718721
return drvPath;
719722
}

0 commit comments

Comments
 (0)