1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2024-12-14 10:13:05 +02:00

Minor updates for bzip2 compression after more review.

Update error types throw by bzip2 to be more consistent with gzip.

Update the bzip2 and gzip error default to be AssertError as that's the more common case in both, and add a 'break;' to the default clause -- we don't intend to be just falling through those case statements, even if the default is the last, we should be explicit about that.

Clean up some tabs that snuck in, rename a variable to be more clear, and add some comments.
This commit is contained in:
Stephen Frost 2020-05-08 16:27:54 -04:00 committed by GitHub
parent 14369c1c3c
commit b4fc1804a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 23 deletions

View File

@ -77,6 +77,8 @@
<release-item> <release-item>
<release-item-contributor-list> <release-item-contributor-list>
<release-item-contributor id="stephen.frost"/> <release-item-contributor id="stephen.frost"/>
<release-item-reviewer id="david.steele"/>
<release-item-reviewer id="cynthia.shang"/>
</release-item-contributor-list> </release-item-contributor-list>
<p>Add <proper>bzip2</proper> compression support.</p> <p>Add <proper>bzip2</proper> compression support.</p>

View File

@ -20,77 +20,71 @@ bz2Error(int error)
if (error < 0) if (error < 0)
{ {
const char *errorMsg; const char *errorMsg;
const ErrorType *errorType = &FormatError; const ErrorType *errorType = &AssertError;
switch (error) switch (error)
{ {
case BZ_SEQUENCE_ERROR: case BZ_SEQUENCE_ERROR:
{ {
errorMsg = "sequence error"; errorMsg = "sequence error";
errorType = &AssertError;
break; break;
} }
case BZ_PARAM_ERROR: case BZ_PARAM_ERROR:
{ {
errorMsg = "parameter error"; errorMsg = "parameter error";
errorType = &AssertError;
break; break;
} }
case BZ_MEM_ERROR: case BZ_MEM_ERROR:
{ {
errorMsg = "memory error"; errorMsg = "memory error";
errorType = &AssertError; errorType = &MemoryError;
break; break;
} }
case BZ_DATA_ERROR: case BZ_DATA_ERROR:
{ {
errorMsg = "data error"; errorMsg = "data error";
errorType = &AssertError; errorType = &FormatError;
break; break;
} }
case BZ_DATA_ERROR_MAGIC: case BZ_DATA_ERROR_MAGIC:
{ {
errorMsg = "data error magic"; errorMsg = "data error magic";
errorType = &AssertError; errorType = &FormatError;
break; break;
} }
case BZ_IO_ERROR: case BZ_IO_ERROR:
{ {
errorMsg = "io error"; errorMsg = "io error";
errorType = &AssertError;
break; break;
} }
case BZ_UNEXPECTED_EOF: case BZ_UNEXPECTED_EOF:
{ {
errorMsg = "unexpected eof"; errorMsg = "unexpected eof";
errorType = &AssertError;
break; break;
} }
case BZ_OUTBUFF_FULL: case BZ_OUTBUFF_FULL:
{ {
errorMsg = "outbuff full"; errorMsg = "outbuff full";
errorType = &AssertError;
break; break;
} }
case BZ_CONFIG_ERROR: case BZ_CONFIG_ERROR:
{ {
errorMsg = "config error"; errorMsg = "config error";
errorType = &AssertError;
break; break;
} }
default: default:
{ {
errorMsg = "unknown error"; errorMsg = "unknown error";
errorType = &AssertError; break;
} }
} }

View File

@ -16,7 +16,7 @@ gzError(int error)
if (error != Z_OK && error != Z_STREAM_END) if (error != Z_OK && error != Z_STREAM_END)
{ {
const char *errorMsg; const char *errorMsg;
const ErrorType *errorType = &FormatError; const ErrorType *errorType = &AssertError;
switch (error) switch (error)
{ {
@ -24,7 +24,6 @@ gzError(int error)
case Z_NEED_DICT: case Z_NEED_DICT:
{ {
errorMsg = "need dictionary"; errorMsg = "need dictionary";
errorType = &AssertError;
break; break;
} }
@ -32,19 +31,20 @@ gzError(int error)
case Z_ERRNO: case Z_ERRNO:
{ {
errorMsg = "file error"; errorMsg = "file error";
errorType = &AssertError;
break; break;
} }
case Z_STREAM_ERROR: case Z_STREAM_ERROR:
{ {
errorMsg = "stream error"; errorMsg = "stream error";
errorType = &FormatError;
break; break;
} }
case Z_DATA_ERROR: case Z_DATA_ERROR:
{ {
errorMsg = "data error"; errorMsg = "data error";
errorType = &FormatError;
break; break;
} }
@ -59,20 +59,20 @@ gzError(int error)
case Z_BUF_ERROR: case Z_BUF_ERROR:
{ {
errorMsg = "no space in buffer"; errorMsg = "no space in buffer";
errorType = &AssertError;
break; break;
} }
case Z_VERSION_ERROR: case Z_VERSION_ERROR:
{ {
errorMsg = "incompatible version"; errorMsg = "incompatible version";
errorType = &FormatError;
break; break;
} }
default: default:
{ {
errorMsg = "unknown error"; errorMsg = "unknown error";
errorType = &AssertError; break;
} }
} }

View File

@ -150,10 +150,12 @@ testSuite(CompressType type, const char *decompressCmd)
TEST_TITLE("compress a large non-zero input buffer into small output buffer"); TEST_TITLE("compress a large non-zero input buffer into small output buffer");
decompressed = bufNew(1024 * 1024 - 1); decompressed = bufNew(1024 * 1024 - 1);
unsigned char *c = bufPtr(decompressed); unsigned char *chr = bufPtr(decompressed);
for (size_t i = 0; i < bufSize(decompressed); i++) // Step through the buffer, setting the individual bytes in a simple pattern (visible ASCII characters, DEC 32 - 126), to make
c[i] = (unsigned char)(i % 94 + 32); // sure that we fill the compression library's small output buffer
for (size_t chrIdx = 0; chrIdx < bufSize(decompressed); chrIdx++)
chr[chrIdx] = (unsigned char)(chrIdx % 94 + 32);
bufUsedSet(decompressed, bufSize(decompressed)); bufUsedSet(decompressed, bufSize(decompressed));
@ -223,9 +225,9 @@ testRun(void)
TEST_RESULT_INT(bz2Error(BZ_STREAM_END), BZ_STREAM_END, "check stream end"); TEST_RESULT_INT(bz2Error(BZ_STREAM_END), BZ_STREAM_END, "check stream end");
TEST_ERROR(bz2Error(BZ_SEQUENCE_ERROR), AssertError, "bz2 error: [-1] sequence error"); TEST_ERROR(bz2Error(BZ_SEQUENCE_ERROR), AssertError, "bz2 error: [-1] sequence error");
TEST_ERROR(bz2Error(BZ_PARAM_ERROR), AssertError, "bz2 error: [-2] parameter error"); TEST_ERROR(bz2Error(BZ_PARAM_ERROR), AssertError, "bz2 error: [-2] parameter error");
TEST_ERROR(bz2Error(BZ_MEM_ERROR), AssertError, "bz2 error: [-3] memory error"); TEST_ERROR(bz2Error(BZ_MEM_ERROR), MemoryError, "bz2 error: [-3] memory error");
TEST_ERROR(bz2Error(BZ_DATA_ERROR), AssertError, "bz2 error: [-4] data error"); TEST_ERROR(bz2Error(BZ_DATA_ERROR), FormatError, "bz2 error: [-4] data error");
TEST_ERROR(bz2Error(BZ_DATA_ERROR_MAGIC), AssertError, "bz2 error: [-5] data error magic"); TEST_ERROR(bz2Error(BZ_DATA_ERROR_MAGIC), FormatError, "bz2 error: [-5] data error magic");
TEST_ERROR(bz2Error(BZ_IO_ERROR), AssertError, "bz2 error: [-6] io error"); TEST_ERROR(bz2Error(BZ_IO_ERROR), AssertError, "bz2 error: [-6] io error");
TEST_ERROR(bz2Error(BZ_UNEXPECTED_EOF), AssertError, "bz2 error: [-7] unexpected eof"); TEST_ERROR(bz2Error(BZ_UNEXPECTED_EOF), AssertError, "bz2 error: [-7] unexpected eof");
TEST_ERROR(bz2Error(BZ_OUTBUFF_FULL), AssertError, "bz2 error: [-8] outbuff full"); TEST_ERROR(bz2Error(BZ_OUTBUFF_FULL), AssertError, "bz2 error: [-8] outbuff full");