about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2016-04-28T12·27+0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2016-04-28T12·27+0200
commit21e9d183ccf4216a61e0bb89d7e2eb42ce092e85 (patch)
tree73d93c91c10f0e70f6e91678efd6ac955b4b8020 /src
parentce5776758d8f40ad5176e70916c71da3194dfcc3 (diff)
Really handle carriage return
Diffstat (limited to 'src')
-rw-r--r--src/libstore/build.cc13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/libstore/build.cc b/src/libstore/build.cc
index 97433821af58..050a48ef0b05 100644
--- a/src/libstore/build.cc
+++ b/src/libstore/build.cc
@@ -751,6 +751,7 @@ private:
     std::list<std::string> 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;
 }