forked from lix-project/lix
"nix-store -l": support compressed logs
This commit is contained in:
parent
4bc4da331a
commit
881beb170d
|
@ -5,7 +5,7 @@ nix_store_SOURCES = \
|
|||
xmlgraph.cc xmlgraph.hh
|
||||
|
||||
nix_store_LDADD = ../libmain/libmain.la ../libstore/libstore.la ../libutil/libutil.la \
|
||||
../boost/format/libformat.la
|
||||
../boost/format/libformat.la -lbz2
|
||||
|
||||
nix-store.o: help.txt.hh
|
||||
|
||||
|
|
|
@ -10,6 +10,13 @@
|
|||
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <bzlib.h>
|
||||
|
||||
|
||||
using namespace nix;
|
||||
|
@ -419,21 +426,39 @@ static void opReadLog(Strings opFlags, Strings opArgs)
|
|||
{
|
||||
if (!opFlags.empty()) throw UsageError("unknown flag");
|
||||
|
||||
for (Strings::iterator i = opArgs.begin();
|
||||
i != opArgs.end(); ++i)
|
||||
{
|
||||
foreach (Strings::iterator, i, opArgs) {
|
||||
Path path = useDeriver(followLinksToStorePath(*i));
|
||||
|
||||
Path logPath = (format("%1%/%2%/%3%") %
|
||||
nixLogDir % drvsLogDir % baseNameOf(path)).str();
|
||||
Path logBz2Path = logPath + ".bz2";
|
||||
|
||||
if (!pathExists(logPath))
|
||||
throw Error(format("build log of derivation `%1%' is not available") % path);
|
||||
|
||||
if (pathExists(logPath)) {
|
||||
/* !!! Make this run in O(1) memory. */
|
||||
string log = readFile(logPath);
|
||||
writeFull(STDOUT_FILENO, (const unsigned char *) log.data(), log.size());
|
||||
}
|
||||
|
||||
else if (pathExists(logBz2Path)) {
|
||||
AutoCloseFD fd = open(logBz2Path.c_str(), O_RDONLY);
|
||||
FILE * f = 0;
|
||||
if (fd == -1 || (f = fdopen(fd.borrow(), "r")) == 0)
|
||||
throw SysError(format("opening file `%1%'") % logBz2Path);
|
||||
int err;
|
||||
BZFILE * bz = BZ2_bzReadOpen(&err, f, 0, 0, 0, 0);
|
||||
if (!bz) throw Error(format("cannot open bzip2 file `%1%'") % logBz2Path);
|
||||
unsigned char buf[128 * 1024];
|
||||
do {
|
||||
int n = BZ2_bzRead(&err, bz, buf, sizeof(buf));
|
||||
if (err != BZ_OK && err != BZ_STREAM_END)
|
||||
throw Error(format("error reading bzip2 file `%1%'") % logBz2Path);
|
||||
writeFull(STDOUT_FILENO, buf, n);
|
||||
} while (err != BZ_STREAM_END);
|
||||
BZ2_bzReadClose(&err, bz);
|
||||
}
|
||||
|
||||
else throw Error(format("build log of derivation `%1%' is not available") % path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue