From 21e9d183ccf4216a61e0bb89d7e2eb42ce092e85 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 28 Apr 2016 14:27:00 +0200 Subject: [PATCH] Really handle carriage return --- src/libstore/build.cc | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/libstore/build.cc b/src/libstore/build.cc index 97433821a..050a48ef0 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -751,6 +751,7 @@ private: std::list logTail; std::string currentLogLine; + size_t currentLogLinePos = 0; // to handle carriage return /* Pipe for the builder's standard output/error. */ Pipe builderOut; @@ -2937,11 +2938,14 @@ void DerivationGoal::handleChildOutput(int fd, const string & data) for (auto c : data) if (c == '\r') - currentLogLine.clear(); // FIXME: not quite right + currentLogLinePos = 0; else if (c == '\n') flushLine(); - else - currentLogLine += c; + else { + if (currentLogLinePos >= currentLogLine.size()) + currentLogLine.resize(currentLogLinePos + 1); + currentLogLine[currentLogLinePos++] = c; + } if (bzLogFile) { int err; @@ -2958,7 +2962,7 @@ void DerivationGoal::handleChildOutput(int fd, const string & data) void DerivationGoal::handleEOF(int fd) { - flushLine(); + if (!currentLogLine.empty()) flushLine(); worker.wakeUp(shared_from_this()); } @@ -2972,6 +2976,7 @@ void DerivationGoal::flushLine() if (logTail.size() > settings.logLines) logTail.pop_front(); } currentLogLine = ""; + currentLogLinePos = 0; }