forked from lix-project/lix
LocalFSStore::getBuildLog(): Handle corrupted logs
This commit is contained in:
parent
ed5c0f69f2
commit
895a74a814
|
@ -94,6 +94,7 @@ std::shared_ptr<std::string> LocalFSStore::getBuildLog(const Path & path_)
|
||||||
|
|
||||||
assertStorePath(path);
|
assertStorePath(path);
|
||||||
|
|
||||||
|
|
||||||
if (!isDerivation(path)) {
|
if (!isDerivation(path)) {
|
||||||
try {
|
try {
|
||||||
path = queryPathInfo(path)->deriver;
|
path = queryPathInfo(path)->deriver;
|
||||||
|
@ -116,8 +117,12 @@ std::shared_ptr<std::string> LocalFSStore::getBuildLog(const Path & path_)
|
||||||
if (pathExists(logPath))
|
if (pathExists(logPath))
|
||||||
return std::make_shared<std::string>(readFile(logPath));
|
return std::make_shared<std::string>(readFile(logPath));
|
||||||
|
|
||||||
else if (pathExists(logBz2Path))
|
else if (pathExists(logBz2Path)) {
|
||||||
|
try {
|
||||||
return decompress("bzip2", readFile(logBz2Path));
|
return decompress("bzip2", readFile(logBz2Path));
|
||||||
|
} catch (Error &) { }
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
|
@ -18,7 +18,7 @@ static ref<std::string> decompressXZ(const std::string & in)
|
||||||
lzma_ret ret = lzma_stream_decoder(
|
lzma_ret ret = lzma_stream_decoder(
|
||||||
&strm, UINT64_MAX, LZMA_CONCATENATED);
|
&strm, UINT64_MAX, LZMA_CONCATENATED);
|
||||||
if (ret != LZMA_OK)
|
if (ret != LZMA_OK)
|
||||||
throw Error("unable to initialise lzma decoder");
|
throw CompressionError("unable to initialise lzma decoder");
|
||||||
|
|
||||||
Finally free([&]() { lzma_end(&strm); });
|
Finally free([&]() { lzma_end(&strm); });
|
||||||
|
|
||||||
|
@ -48,10 +48,10 @@ static ref<std::string> decompressXZ(const std::string & in)
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
if (ret != LZMA_OK)
|
if (ret != LZMA_OK)
|
||||||
throw Error("error while decompressing xz file");
|
throw CompressionError("error while decompressing xz file");
|
||||||
|
|
||||||
if (strm.avail_in == 0)
|
if (strm.avail_in == 0)
|
||||||
throw Error("xz data ends prematurely");
|
throw CompressionError("xz data ends prematurely");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ static ref<std::string> decompressBzip2(const std::string & in)
|
||||||
|
|
||||||
int ret = BZ2_bzDecompressInit(&strm, 0, 0);
|
int ret = BZ2_bzDecompressInit(&strm, 0, 0);
|
||||||
if (ret != BZ_OK)
|
if (ret != BZ_OK)
|
||||||
throw Error("unable to initialise bzip2 decoder");
|
throw CompressionError("unable to initialise bzip2 decoder");
|
||||||
|
|
||||||
Finally free([&]() { BZ2_bzDecompressEnd(&strm); });
|
Finally free([&]() { BZ2_bzDecompressEnd(&strm); });
|
||||||
|
|
||||||
|
@ -88,10 +88,10 @@ static ref<std::string> decompressBzip2(const std::string & in)
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
if (ret != BZ_OK)
|
if (ret != BZ_OK)
|
||||||
throw Error("error while decompressing bzip2 file");
|
throw CompressionError("error while decompressing bzip2 file");
|
||||||
|
|
||||||
if (strm.avail_in == 0)
|
if (strm.avail_in == 0)
|
||||||
throw Error("bzip2 data ends prematurely");
|
throw CompressionError("bzip2 data ends prematurely");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ struct XzSink : CompressionSink
|
||||||
lzma_ret ret = lzma_easy_encoder(
|
lzma_ret ret = lzma_easy_encoder(
|
||||||
&strm, 6, LZMA_CHECK_CRC64);
|
&strm, 6, LZMA_CHECK_CRC64);
|
||||||
if (ret != LZMA_OK)
|
if (ret != LZMA_OK)
|
||||||
throw Error("unable to initialise lzma encoder");
|
throw CompressionError("unable to initialise lzma encoder");
|
||||||
// FIXME: apply the x86 BCJ filter?
|
// FIXME: apply the x86 BCJ filter?
|
||||||
|
|
||||||
strm.next_out = outbuf;
|
strm.next_out = outbuf;
|
||||||
|
@ -168,7 +168,7 @@ struct XzSink : CompressionSink
|
||||||
|
|
||||||
lzma_ret ret = lzma_code(&strm, LZMA_FINISH);
|
lzma_ret ret = lzma_code(&strm, LZMA_FINISH);
|
||||||
if (ret != LZMA_OK && ret != LZMA_STREAM_END)
|
if (ret != LZMA_OK && ret != LZMA_STREAM_END)
|
||||||
throw Error("error while flushing xz file");
|
throw CompressionError("error while flushing xz file");
|
||||||
|
|
||||||
if (strm.avail_out == 0 || ret == LZMA_STREAM_END) {
|
if (strm.avail_out == 0 || ret == LZMA_STREAM_END) {
|
||||||
nextSink(outbuf, sizeof(outbuf) - strm.avail_out);
|
nextSink(outbuf, sizeof(outbuf) - strm.avail_out);
|
||||||
|
@ -192,7 +192,7 @@ struct XzSink : CompressionSink
|
||||||
|
|
||||||
lzma_ret ret = lzma_code(&strm, LZMA_RUN);
|
lzma_ret ret = lzma_code(&strm, LZMA_RUN);
|
||||||
if (ret != LZMA_OK)
|
if (ret != LZMA_OK)
|
||||||
throw Error("error while compressing xz file");
|
throw CompressionError("error while compressing xz file");
|
||||||
|
|
||||||
if (strm.avail_out == 0) {
|
if (strm.avail_out == 0) {
|
||||||
nextSink(outbuf, sizeof(outbuf));
|
nextSink(outbuf, sizeof(outbuf));
|
||||||
|
@ -215,7 +215,7 @@ struct BzipSink : CompressionSink
|
||||||
memset(&strm, 0, sizeof(strm));
|
memset(&strm, 0, sizeof(strm));
|
||||||
int ret = BZ2_bzCompressInit(&strm, 9, 0, 30);
|
int ret = BZ2_bzCompressInit(&strm, 9, 0, 30);
|
||||||
if (ret != BZ_OK)
|
if (ret != BZ_OK)
|
||||||
throw Error("unable to initialise bzip2 encoder");
|
throw CompressionError("unable to initialise bzip2 encoder");
|
||||||
|
|
||||||
strm.next_out = outbuf;
|
strm.next_out = outbuf;
|
||||||
strm.avail_out = sizeof(outbuf);
|
strm.avail_out = sizeof(outbuf);
|
||||||
|
@ -238,7 +238,7 @@ struct BzipSink : CompressionSink
|
||||||
|
|
||||||
int ret = BZ2_bzCompress(&strm, BZ_FINISH);
|
int ret = BZ2_bzCompress(&strm, BZ_FINISH);
|
||||||
if (ret != BZ_FINISH_OK && ret != BZ_STREAM_END)
|
if (ret != BZ_FINISH_OK && ret != BZ_STREAM_END)
|
||||||
throw Error("error while flushing bzip2 file");
|
throw CompressionError("error while flushing bzip2 file");
|
||||||
|
|
||||||
if (strm.avail_out == 0 || ret == BZ_STREAM_END) {
|
if (strm.avail_out == 0 || ret == BZ_STREAM_END) {
|
||||||
nextSink((unsigned char *) outbuf, sizeof(outbuf) - strm.avail_out);
|
nextSink((unsigned char *) outbuf, sizeof(outbuf) - strm.avail_out);
|
||||||
|
@ -262,7 +262,7 @@ struct BzipSink : CompressionSink
|
||||||
|
|
||||||
int ret = BZ2_bzCompress(&strm, BZ_RUN);
|
int ret = BZ2_bzCompress(&strm, BZ_RUN);
|
||||||
if (ret != BZ_OK)
|
if (ret != BZ_OK)
|
||||||
Error("error while compressing bzip2 file");
|
CompressionError("error while compressing bzip2 file");
|
||||||
|
|
||||||
if (strm.avail_out == 0) {
|
if (strm.avail_out == 0) {
|
||||||
nextSink((unsigned char *) outbuf, sizeof(outbuf));
|
nextSink((unsigned char *) outbuf, sizeof(outbuf));
|
||||||
|
|
|
@ -21,4 +21,6 @@ ref<CompressionSink> makeCompressionSink(const std::string & method, Sink & next
|
||||||
|
|
||||||
MakeError(UnknownCompressionMethod, Error);
|
MakeError(UnknownCompressionMethod, Error);
|
||||||
|
|
||||||
|
MakeError(CompressionError, Error);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue