aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/libutil/file-descriptor.cc6
-rw-r--r--src/libutil/file-descriptor.hh3
-rw-r--r--src/libutil/processes.cc2
3 files changed, 6 insertions, 5 deletions
diff --git a/src/libutil/file-descriptor.cc b/src/libutil/file-descriptor.cc
index a19ceaf2a..ab69b5754 100644
--- a/src/libutil/file-descriptor.cc
+++ b/src/libutil/file-descriptor.cc
@@ -81,12 +81,12 @@ std::string drainFD(int fd, bool block, const size_t reserveSize)
// the parser needs two extra bytes to append terminating characters, other users will
// not care very much about the extra memory.
StringSink sink(reserveSize + 2);
- drainFD(fd, sink, block);
+ sink << drainFDSource(fd, block);
return std::move(sink.s);
}
-void drainFD(int fd, Sink & sink, bool block)
+Generator<Bytes> drainFDSource(int fd, bool block)
{
// silence GCC maybe-uninitialized warning in finally
int saved = 0;
@@ -115,7 +115,7 @@ void drainFD(int fd, Sink & sink, bool block)
throw SysError("reading from file");
}
else if (rd == 0) break;
- else sink({(char *) buf.data(), (size_t) rd});
+ else co_yield std::span{(char *) buf.data(), (size_t) rd};
}
}
diff --git a/src/libutil/file-descriptor.hh b/src/libutil/file-descriptor.hh
index f59baa7a0..a83bc028f 100644
--- a/src/libutil/file-descriptor.hh
+++ b/src/libutil/file-descriptor.hh
@@ -2,6 +2,7 @@
///@file
#include "error.hh"
+#include "generator.hh"
namespace nix {
@@ -35,7 +36,7 @@ void writeFull(int fd, std::string_view s, bool allowInterrupts = true);
*/
std::string drainFD(int fd, bool block = true, const size_t reserveSize=0);
-void drainFD(int fd, Sink & sink, bool block = true);
+Generator<Bytes> drainFDSource(int fd, bool block = true);
class AutoCloseFD
{
diff --git a/src/libutil/processes.cc b/src/libutil/processes.cc
index 250092393..bd5ccdb4b 100644
--- a/src/libutil/processes.cc
+++ b/src/libutil/processes.cc
@@ -315,7 +315,7 @@ void runProgram2(const RunOptions & options)
out.writeSide.close();
if (options.standardOut)
- drainFD(out.readSide.get(), *options.standardOut);
+ *options.standardOut << drainFDSource(out.readSide.get());
/* Wait for the child to finish. */
int status = pid.wait();