From 7d295c594e1d100c9dcbdd89198eb3882856cfcb Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 4 Jun 2024 16:05:56 +0200 Subject: [PATCH] Make EvalState::srcToStore thread-safe --- src/libexpr/eval.cc | 8 ++++---- src/libexpr/eval.hh | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 6a38bbe45..7dbb467e5 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -2415,10 +2415,10 @@ StorePath EvalState::copyPathToStore(NixStringContext & context, const SourcePat if (nix::isDerivation(path.path.abs())) error("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, @@ -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; }(); diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index 06a687620..dac763268 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -306,7 +306,7 @@ private: /* Cache for calls to addToStore(); maps source paths to the store paths. */ - std::map srcToStore; + Sync> srcToStore; /** * A cache from path names to parse trees.