aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/store-api.cc
diff options
context:
space:
mode:
authorJade Lovelace <lix@jade.fyi>2024-06-15 16:39:14 -0700
committerJade Lovelace <lix@jade.fyi>2024-06-18 15:11:49 -0700
commit8e6661cce74dba6ed4572e84ab55c77a96a7d9e4 (patch)
treea342308ee611d95ea8a60b7d5a3813f41dab1e5b /src/libstore/store-api.cc
parent9185ab7bf016523809e925773313c1450effa599 (diff)
store-api: fix/clarify capture lifetimes in copyPaths
This seems to fix a use of stack after return. Change-Id: If690a6defb9a3225684685132cf78b227e271447
Diffstat (limited to 'src/libstore/store-api.cc')
-rw-r--r--src/libstore/store-api.cc41
1 files changed, 23 insertions, 18 deletions
diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc
index a10e5df0a..55083e834 100644
--- a/src/libstore/store-api.cc
+++ b/src/libstore/store-api.cc
@@ -1174,25 +1174,30 @@ std::map<StorePath, StorePath> copyPaths(
ValidPathInfo infoForDst = *info;
infoForDst.path = storePathForDst;
- auto source = sinkToSource([&](Sink & sink) {
- // We can reasonably assume that the copy will happen whenever we
- // read the path, so log something about that at that point
- auto srcUri = srcStore.getUri();
- auto dstUri = dstStore.getUri();
- auto storePathS = srcStore.printStorePath(missingPath);
- Activity act(*logger, lvlInfo, actCopyPath,
- makeCopyPathMessage(srcUri, dstUri, storePathS),
- {storePathS, srcUri, dstUri});
- PushActivity pact(act.id);
-
- LambdaSink progressSink([&, total = 0ULL](std::string_view data) mutable {
- total += data.size();
- act.progress(total, info->narSize);
- });
- TeeSink tee { sink, progressSink };
+ auto source =
+ sinkToSource([&srcStore, &dstStore, missingPath = missingPath, info = std::move(info)](Sink & sink) {
+ // We can reasonably assume that the copy will happen whenever we
+ // read the path, so log something about that at that point
+ auto srcUri = srcStore.getUri();
+ auto dstUri = dstStore.getUri();
+ auto storePathS = srcStore.printStorePath(missingPath);
+ Activity act(
+ *logger,
+ lvlInfo,
+ actCopyPath,
+ makeCopyPathMessage(srcUri, dstUri, storePathS),
+ {storePathS, srcUri, dstUri}
+ );
+ PushActivity pact(act.id);
+
+ LambdaSink progressSink([&, total = 0ULL](std::string_view data) mutable {
+ total += data.size();
+ act.progress(total, info->narSize);
+ });
+ TeeSink tee{sink, progressSink};
- srcStore.narFromPath(missingPath, tee);
- });
+ srcStore.narFromPath(missingPath, tee);
+ });
pathsToCopy.push_back(std::pair{infoForDst, std::move(source)});
}