summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2012-07-17 09:40:12 -0400
committerEelco Dolstra <eelco.dolstra@logicblox.com>2012-07-17 09:40:12 -0400
commit53b24f351852498c52377c2f011617af04bc76fa (patch)
tree39b5940695ca8157c8d8eeab875f1e439b1aa731 /src
parenta7a43adb79393084a27589bc929e5a22877ba944 (diff)
downloadguix-53b24f351852498c52377c2f011617af04bc76fa.tar.gz
Allow disabling log compression
Diffstat (limited to 'src')
-rw-r--r--src/libstore/build.cc37
1 files changed, 25 insertions, 12 deletions
diff --git a/src/libstore/build.cc b/src/libstore/build.cc
index d5bbd540b3..8eb5dfa41b 100644
--- a/src/libstore/build.cc
+++ b/src/libstore/build.cc
@@ -769,6 +769,7 @@ private:
     /* File descriptor for the log file. */
     FILE * fLogFile;
     BZFILE * bzLogFile;
+    AutoCloseFD fdLogFile;
 
     /* Pipe for the builder's standard output/error. */
     Pipe builderOut;
@@ -2119,20 +2120,29 @@ Path DerivationGoal::openLogFile()
     Path dir = (format("%1%/%2%") % nixLogDir % drvsLogDir).str();
     createDirs(dir);
 
-    Path logFileName = (format("%1%/%2%.bz2") % dir % baseNameOf(drvPath)).str();
-    AutoCloseFD fd = open(logFileName.c_str(), O_CREAT | O_WRONLY | O_TRUNC, 0666);
-    if (fd == -1)
-        throw SysError(format("creating log file `%1%'") % logFileName);
-    closeOnExec(fd);
+    if (queryBoolSetting("build-compress-log", true)) {
 
-    if (!(fLogFile = fdopen(fd.borrow(), "w")))
-        throw SysError(format("opening file `%1%'") % logFileName);
+        Path logFileName = (format("%1%/%2%.bz2") % dir % baseNameOf(drvPath)).str();
+        AutoCloseFD fd = open(logFileName.c_str(), O_CREAT | O_WRONLY | O_TRUNC, 0666);
+        if (fd == -1) throw SysError(format("creating log file `%1%'") % logFileName);
+        closeOnExec(fd);
+
+        if (!(fLogFile = fdopen(fd.borrow(), "w")))
+            throw SysError(format("opening file `%1%'") % logFileName);
+
+        int err;
+        if (!(bzLogFile = BZ2_bzWriteOpen(&err, fLogFile, 9, 0, 0)))
+            throw Error(format("cannot open compressed log file `%1%'") % logFileName);
 
-    int err;
-    if (!(bzLogFile = BZ2_bzWriteOpen(&err, fLogFile, 9, 0, 0)))
-        throw Error(format("cannot open compressed log file `%1%'") % logFileName);
+        return logFileName;
 
-    return logFileName;
+    } else {
+        Path logFileName = (format("%1%/%2%") % dir % baseNameOf(drvPath)).str();
+        fdLogFile = open(logFileName.c_str(), O_CREAT | O_WRONLY | O_TRUNC, 0666);
+        if (fdLogFile == -1) throw SysError(format("creating log file `%1%'") % logFileName);
+        closeOnExec(fdLogFile);
+        return logFileName;
+    }
 }
 
 
@@ -2149,6 +2159,8 @@ void DerivationGoal::closeLogFile()
         fclose(fLogFile);
         fLogFile = 0;
     }
+
+    fdLogFile.close();
 }
 
 
@@ -2180,7 +2192,8 @@ void DerivationGoal::handleChildOutput(int fd, const string & data)
             int err;
             BZ2_bzWrite(&err, bzLogFile, (unsigned char *) data.data(), data.size());
             if (err != BZ_OK) throw Error(format("cannot write to compressed log file (BZip2 error = %1%)") % err);
-        }
+        } else if (fdLogFile != -1)
+            writeFull(fdLogFile, (unsigned char *) data.data(), data.size());
     }
 
     if (hook && fd == hook->fromHook.readSide)