Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/libfetchers/fetch-to-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ std::pair<StorePath, Hash> fetchToStore2(
auto hash = Hash::parseSRI(fetchers::getStrAttr(*res, "hash"));
auto storePath =
store.makeFixedOutputPathFromCA(name, ContentAddressWithReferences::fromParts(method, hash, {}));

/* Add a temproot before the call to isValidPath to prevent accidental GC in case the
input is cached. Note that this must be done before to avoid races. */
if (mode != FetchMode::DryRun)
store.addTempRoot(storePath);

if (mode == FetchMode::DryRun || store.maybeQueryPathInfo(storePath)) {
debug(
"source path '%s' cache hit in '%s' (hash '%s')",
Expand Down
1 change: 1 addition & 0 deletions src/libstore/async-path-writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ struct AsyncPathWriterImpl : AsyncPathWriter

for (auto & item : items) {
StringSource source(item.contents);
store->addTempRoot(item.storePath);
auto storePath = store->addToStoreFromDump(
source,
Comment on lines 164 to 165

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw I think that in this case the remote side already adds temp roots https://github.com/NixOS/nix/blob/fa1a370c6fb827883d1d34317f31f948a1f44b7b/src/libstore/local-store.cc#L1210

It's more of the pattern of isValidPath that needs to have a temp root added first.

item.storePath.name(),
Expand Down
6 changes: 6 additions & 0 deletions src/libstore/derivations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ Store::writeDerivation(const Derivation & drv, RepairFlag repair, std::shared_pt
{
auto [suffix, contents, references, path] = infoForDerivation(*this, drv);

/* In case the derivation is already valid, we bail out early since that's
faster. But we need to make sure that the derivation has a corresponding
temproot. It is added by the remote in addToStoreFromDump, but we'd like
to avoid sending a lot of drv contents to the daemon. */
addTempRoot(path);

if (isValidPath(path) && !repair)
return path;

Expand Down