sourceToSink(): Throw EndOfFile

This commit is contained in:
Eelco Dolstra 2024-07-22 15:18:58 +02:00
parent 0194f81587
commit 609df83c01
2 changed files with 4 additions and 6 deletions

View file

@ -1245,7 +1245,6 @@ StorePath LocalStore::addToStoreFromDump(
}); });
try { try {
got = source.read(dumpBuffer.get() + oldSize, want); got = source.read(dumpBuffer.get() + oldSize, want);
if (!got) break;
} catch (EndOfFile &) { } catch (EndOfFile &) {
inMemory = true; inMemory = true;
break; break;

View file

@ -246,9 +246,8 @@ std::unique_ptr<FinishSink> sourceToSink(std::function<void(Source &)> fun)
LambdaSource source([&](char * out, size_t out_len) { LambdaSource source([&](char * out, size_t out_len) {
if (cur.empty()) { if (cur.empty()) {
yield(); yield();
if (yield.get()) { if (yield.get())
return (size_t) 0; throw EndOfFile("coroutine has finished");
}
} }
size_t n = std::min(cur.size(), out_len); size_t n = std::min(cur.size(), out_len);
@ -271,12 +270,12 @@ std::unique_ptr<FinishSink> sourceToSink(std::function<void(Source &)> fun)
void finish() override void finish() override
{ {
if (!coro) return; if (!coro) return;
//if (!*coro) abort(); if (!*coro) abort();
{ {
CoroutineContext ctx; CoroutineContext ctx;
(*coro)(true); (*coro)(true);
} }
//if (*coro) abort(); if (*coro) abort();
} }
}; };