Skip to content

Commit

Permalink
Make EvalState::srcToStore thread-safe
Browse files Browse the repository at this point in the history
  • Loading branch information
edolstra committed Jun 4, 2024
1 parent b36aa04 commit 7d295c5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/libexpr/eval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2415,10 +2415,10 @@ StorePath EvalState::copyPathToStore(NixStringContext & context, const SourcePat
if (nix::isDerivation(path.path.abs()))
error<EvalError>("file names are not allowed to end in '%1%'", drvExtension).debugThrow();

auto i = srcToStore.find(path);
auto dstPathCached = get(*srcToStore.lock(), path);

auto dstPath = i != srcToStore.end()
? i->second
auto dstPath = dstPathCached
? *dstPathCached
: [&]() {
auto dstPath = fetchToStore(
*store,
Expand All @@ -2429,7 +2429,7 @@ StorePath EvalState::copyPathToStore(NixStringContext & context, const SourcePat
nullptr,
repair);
allowPath(dstPath);
srcToStore.insert_or_assign(path, dstPath);
srcToStore.lock()->try_emplace(path, dstPath);
printMsg(lvlChatty, "copied source '%1%' -> '%2%'", path, store->printStorePath(dstPath));
return dstPath;
}();
Expand Down
2 changes: 1 addition & 1 deletion src/libexpr/eval.hh
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ private:

/* Cache for calls to addToStore(); maps source paths to the store
paths. */
std::map<SourcePath, StorePath> srcToStore;
Sync<std::map<SourcePath, StorePath>> srcToStore;

/**
* A cache from path names to parse trees.
Expand Down

0 comments on commit 7d295c5

Please sign in to comment.