diff options
author | Patrick Jackson <patrick@jackson.dev> | 2023-03-30 16:58:07 -0700 |
---|---|---|
committer | Patrick Jackson <patrick@jackson.dev> | 2023-03-30 16:59:34 -0700 |
commit | 309753ebb5f4d1cae64554fac8d4e49c2c28884c (patch) | |
tree | 8ba35f306ba37def94bd9e82dc6338a3c2787bb5 /src/libstore/store-api.cc | |
parent | 06d87b95bc751480d5961def9c0a21f557103625 (diff) |
Fix data race in copyPaths
Diffstat (limited to 'src/libstore/store-api.cc')
-rw-r--r-- | src/libstore/store-api.cc | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index b0ca1321c..6233768df 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -10,6 +10,7 @@ #include "archive.hh" #include "callback.hh" #include "remote-store.hh" +#include "sync.hh" #include <nlohmann/json.hpp> #include <regex> @@ -1101,7 +1102,8 @@ std::map<StorePath, StorePath> copyPaths( return storePathForDst; }; - uint64_t total = 0; + // total is accessed by each copy, which are each handled in separate threads + Sync<uint64_t> total = 0; for (auto & missingPath : sortedMissing) { auto info = srcStore.queryPathInfo(missingPath); @@ -1124,8 +1126,8 @@ std::map<StorePath, StorePath> copyPaths( PushActivity pact(act.id); LambdaSink progressSink([&](std::string_view data) { - total += data.size(); - act.progress(total, info->narSize); + *total.lock() += data.size(); + act.progress(*total.lock(), info->narSize); }); TeeSink tee { sink, progressSink }; |