aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoreldritch horrors <pennae@lix.systems>2024-04-06 22:08:58 +0200
committereldritch horrors <pennae@lix.systems>2024-06-23 11:52:49 +0000
commit39a1e248c9e7adea312c5b7e1743a8e55da63e6c (patch)
treeb49c7911ad537c1fe6731508535eda19d7c1e2c3 /src
parentf80d95e36dc08c796863680c9ecc6b8f495825b9 (diff)
libutil: remove sinkToSource eof callback
this is only used in one place, and only to set a nicer error message on EndOfFile. the only caller that actually *catches* this exception should provide an error message in that catch block rather than forcing support for setting error message so deep into the stack. copyStorePath is never called outside of PathSubstitutionGoal anyway, which catches everything. Change-Id: Ifbae8706d781c388737706faf4c8a8b7917ca278
Diffstat (limited to 'src')
-rw-r--r--src/libstore/build/substitution-goal.cc12
-rw-r--r--src/libstore/store-api.cc2
-rw-r--r--src/libutil/serialise.cc15
-rw-r--r--src/libutil/serialise.hh6
4 files changed, 18 insertions, 17 deletions
diff --git a/src/libstore/build/substitution-goal.cc b/src/libstore/build/substitution-goal.cc
index d8d9ba283..cc4cb3c8c 100644
--- a/src/libstore/build/substitution-goal.cc
+++ b/src/libstore/build/substitution-goal.cc
@@ -217,6 +217,7 @@ void PathSubstitutionGoal::tryToRun()
promise = std::promise<void>();
thr = std::thread([this]() {
+ auto & fetchPath = subPath ? *subPath : storePath;
try {
ReceiveInterrupts receiveInterrupts;
@@ -226,10 +227,17 @@ void PathSubstitutionGoal::tryToRun()
Activity act(*logger, actSubstitute, Logger::Fields{worker.store.printStorePath(storePath), sub->getUri()});
PushActivity pact(act.id);
- copyStorePath(*sub, worker.store,
- subPath ? *subPath : storePath, repair, sub->isTrusted ? NoCheckSigs : CheckSigs);
+ copyStorePath(
+ *sub, worker.store, fetchPath, repair, sub->isTrusted ? NoCheckSigs : CheckSigs
+ );
promise.set_value();
+ } catch (const EndOfFile &) {
+ promise.set_exception(std::make_exception_ptr(EndOfFile(
+ "NAR for '%s' fetched from '%s' is incomplete",
+ sub->printStorePath(fetchPath),
+ sub->getUri()
+ )));
} catch (...) {
promise.set_exception(std::current_exception());
}
diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc
index 244ecf256..7c0902978 100644
--- a/src/libstore/store-api.cc
+++ b/src/libstore/store-api.cc
@@ -1072,8 +1072,6 @@ void copyStorePath(
});
TeeSink tee { sink, progressSink };
srcStore.narFromPath(storePath, tee);
- }, [&]() {
- throw EndOfFile("NAR for '%s' fetched from '%s' is incomplete", srcStore.printStorePath(storePath), srcStore.getUri());
});
dstStore.addToStore(*info, *source, repair, checkSigs);
diff --git a/src/libutil/serialise.cc b/src/libutil/serialise.cc
index 3a8a01f16..80b111f08 100644
--- a/src/libutil/serialise.cc
+++ b/src/libutil/serialise.cc
@@ -266,20 +266,17 @@ std::unique_ptr<FinishSink> sourceToSink(std::function<void(Source &)> fun)
}
-std::unique_ptr<Source> sinkToSource(
- std::function<void(Sink &)> fun,
- std::function<void()> eof)
+std::unique_ptr<Source> sinkToSource(std::function<void(Sink &)> fun)
{
struct SinkToSource : Source
{
typedef boost::coroutines2::coroutine<std::string> coro_t;
std::function<void(Sink &)> fun;
- std::function<void()> eof;
std::optional<coro_t::pull_type> coro;
- SinkToSource(std::function<void(Sink &)> fun, std::function<void()> eof)
- : fun(fun), eof(eof)
+ SinkToSource(std::function<void(Sink &)> fun)
+ : fun(fun)
{
}
@@ -298,7 +295,9 @@ std::unique_ptr<Source> sinkToSource(
});
}
- if (!*coro) { eof(); abort(); }
+ if (!*coro) {
+ throw EndOfFile("coroutine has finished");
+ }
if (pos == cur.size()) {
if (!cur.empty()) {
@@ -317,7 +316,7 @@ std::unique_ptr<Source> sinkToSource(
}
};
- return std::make_unique<SinkToSource>(fun, eof);
+ return std::make_unique<SinkToSource>(fun);
}
diff --git a/src/libutil/serialise.hh b/src/libutil/serialise.hh
index c9294ba2d..0632e3109 100644
--- a/src/libutil/serialise.hh
+++ b/src/libutil/serialise.hh
@@ -338,11 +338,7 @@ std::unique_ptr<FinishSink> sourceToSink(std::function<void(Source &)> fun);
* Convert a function that feeds data into a Sink into a Source. The
* Source executes the function as a coroutine.
*/
-std::unique_ptr<Source> sinkToSource(
- std::function<void(Sink &)> fun,
- std::function<void()> eof = []() {
- throw EndOfFile("coroutine has finished");
- });
+std::unique_ptr<Source> sinkToSource(std::function<void(Sink &)> fun);
void writePadding(size_t len, Sink & sink);