store-api: fix/clarify capture lifetimes in copyPaths

This seems to fix a use of stack after return.

Change-Id: If690a6defb9a3225684685132cf78b227e271447
This commit is contained in:
jade 2024-06-15 16:39:14 -07:00
parent 9185ab7bf0
commit 8e6661cce7

View file

@ -1174,25 +1174,30 @@ std::map<StorePath, StorePath> copyPaths(
ValidPathInfo infoForDst = *info; ValidPathInfo infoForDst = *info;
infoForDst.path = storePathForDst; infoForDst.path = storePathForDst;
auto source = sinkToSource([&](Sink & sink) { auto source =
// We can reasonably assume that the copy will happen whenever we sinkToSource([&srcStore, &dstStore, missingPath = missingPath, info = std::move(info)](Sink & sink) {
// read the path, so log something about that at that point // We can reasonably assume that the copy will happen whenever we
auto srcUri = srcStore.getUri(); // read the path, so log something about that at that point
auto dstUri = dstStore.getUri(); auto srcUri = srcStore.getUri();
auto storePathS = srcStore.printStorePath(missingPath); auto dstUri = dstStore.getUri();
Activity act(*logger, lvlInfo, actCopyPath, auto storePathS = srcStore.printStorePath(missingPath);
makeCopyPathMessage(srcUri, dstUri, storePathS), Activity act(
{storePathS, srcUri, dstUri}); *logger,
PushActivity pact(act.id); lvlInfo,
actCopyPath,
makeCopyPathMessage(srcUri, dstUri, storePathS),
{storePathS, srcUri, dstUri}
);
PushActivity pact(act.id);
LambdaSink progressSink([&, total = 0ULL](std::string_view data) mutable { LambdaSink progressSink([&, total = 0ULL](std::string_view data) mutable {
total += data.size(); total += data.size();
act.progress(total, info->narSize); act.progress(total, info->narSize);
});
TeeSink tee{sink, progressSink};
srcStore.narFromPath(missingPath, tee);
}); });
TeeSink tee { sink, progressSink };
srcStore.narFromPath(missingPath, tee);
});
pathsToCopy.push_back(std::pair{infoForDst, std::move(source)}); pathsToCopy.push_back(std::pair{infoForDst, std::move(source)});
} }