You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-09-16 09:06:18 +02:00
Add bufEmpty().
This seems more readable than bufUsed() == 0, just like 7d6c0319
.
This commit is contained in:
@@ -93,7 +93,7 @@ lz4CompressBuffer(Lz4Compress *this, size_t required, Buffer *output)
|
||||
Buffer *result = output;
|
||||
|
||||
// Is an internal buffer required to hold the compressed data?
|
||||
if (bufUsed(this->buffer) > 0 || required >= bufRemains(output))
|
||||
if (!bufEmpty(this->buffer) || required >= bufRemains(output))
|
||||
{
|
||||
// Reallocate buffer if it is not large enough
|
||||
if (required >= bufRemains(this->buffer))
|
||||
|
@@ -267,7 +267,7 @@ cipherBlockProcess(THIS_VOID, const Buffer *source, Buffer *destination)
|
||||
ASSERT(bufRemains(destination) > 0);
|
||||
|
||||
// Copy already buffered bytes
|
||||
if (this->buffer != NULL && bufUsed(this->buffer) > 0)
|
||||
if (this->buffer != NULL && !bufEmpty(this->buffer))
|
||||
{
|
||||
if (bufRemains(destination) >= bufUsed(this->buffer))
|
||||
{
|
||||
@@ -289,7 +289,7 @@ cipherBlockProcess(THIS_VOID, const Buffer *source, Buffer *destination)
|
||||
}
|
||||
else
|
||||
{
|
||||
ASSERT(this->buffer == NULL || bufUsed(this->buffer) == 0);
|
||||
ASSERT(this->buffer == NULL || bufEmpty(this->buffer));
|
||||
|
||||
// Determine how much space is required in the output buffer
|
||||
Buffer *outputActual = destination;
|
||||
@@ -339,7 +339,7 @@ cipherBlockProcess(THIS_VOID, const Buffer *source, Buffer *destination)
|
||||
bufUsedInc(outputActual, destinationSizeActual);
|
||||
|
||||
// Copy from buffer to destination if needed
|
||||
if (this->buffer != NULL && bufUsed(this->buffer) > 0)
|
||||
if (this->buffer != NULL && !bufEmpty(this->buffer))
|
||||
cipherBlockProcess(this, source, destination);
|
||||
}
|
||||
|
||||
@@ -392,7 +392,7 @@ cipherBlockNew(CipherMode mode, CipherType cipherType, const Buffer *pass, const
|
||||
FUNCTION_LOG_END();
|
||||
|
||||
ASSERT(pass != NULL);
|
||||
ASSERT(bufUsed(pass) > 0);
|
||||
ASSERT(!bufEmpty(pass));
|
||||
|
||||
// Init crypto subsystem
|
||||
cryptoInit();
|
||||
|
@@ -242,7 +242,7 @@ cryptoHashOne(const String *type, const Buffer *message)
|
||||
{
|
||||
IoFilter *hash = cryptoHashNew(type);
|
||||
|
||||
if (bufUsed(message) > 0)
|
||||
if (!bufEmpty(message))
|
||||
ioFilterProcessIn(hash, message);
|
||||
|
||||
const Buffer *buffer = cryptoHash((CryptoHash *)ioFilterDriver(hash));
|
||||
|
@@ -73,7 +73,7 @@ ioFilterProcessIn(IoFilter *this, const Buffer *input)
|
||||
|
||||
ASSERT(this != NULL);
|
||||
ASSERT(this->interface.in != NULL);
|
||||
CHECK(input == NULL || bufUsed(input) > 0);
|
||||
CHECK(input == NULL || !bufEmpty(input));
|
||||
CHECK(!this->flushing || input == NULL);
|
||||
|
||||
if (input == NULL)
|
||||
@@ -97,7 +97,7 @@ ioFilterProcessInOut(IoFilter *this, const Buffer *input, Buffer *output)
|
||||
ASSERT(this != NULL);
|
||||
ASSERT(output != NULL);
|
||||
ASSERT(this->interface.inOut != NULL);
|
||||
CHECK(input == NULL || bufUsed(input) > 0);
|
||||
CHECK(input == NULL || !bufEmpty(input));
|
||||
CHECK(!this->flushing || input == NULL);
|
||||
|
||||
if (input == NULL && !this->flushing)
|
||||
@@ -106,7 +106,7 @@ ioFilterProcessInOut(IoFilter *this, const Buffer *input, Buffer *output)
|
||||
if (!ioFilterDone(this))
|
||||
this->interface.inOut(this->driver, input, output);
|
||||
|
||||
CHECK(!ioFilterInputSame(this) || bufUsed(output) > 0);
|
||||
CHECK(!ioFilterInputSame(this) || !bufEmpty(output));
|
||||
FUNCTION_TEST_RETURN_VOID();
|
||||
}
|
||||
|
||||
|
@@ -235,7 +235,7 @@ ioFilterGroupProcess(IoFilterGroup *this, const Buffer *input, Buffer *output)
|
||||
|
||||
ASSERT(this != NULL);
|
||||
ASSERT(this->opened && !this->closed);
|
||||
ASSERT(input == NULL || bufUsed(input) > 0);
|
||||
ASSERT(input == NULL || !bufEmpty(input));
|
||||
ASSERT(!this->flushing || input == NULL);
|
||||
ASSERT(output != NULL);
|
||||
ASSERT(bufRemains(output) > 0);
|
||||
|
@@ -295,7 +295,7 @@ httpRequestError(const HttpRequest *this, HttpResponse *response)
|
||||
}
|
||||
|
||||
// Add response content, if any
|
||||
if (bufUsed(httpResponseContent(response)) > 0)
|
||||
if (!bufEmpty(httpResponseContent(response)))
|
||||
{
|
||||
strCatZ(error, "\n*** Response Content ***:\n");
|
||||
strCat(error, strNewBuf(httpResponseContent(response)));
|
||||
|
@@ -158,7 +158,7 @@ ioReadInternal(IoRead *this, Buffer *buffer, bool block)
|
||||
}
|
||||
|
||||
// Process the input buffer (or flush if NULL)
|
||||
if (this->input == NULL || bufUsed(this->input) > 0)
|
||||
if (this->input == NULL || !bufEmpty(this->input))
|
||||
ioFilterGroupProcess(this->filterGroup, this->input, buffer);
|
||||
|
||||
// Stop if not blocking -- we don't need to fill the buffer as long as we got some data
|
||||
|
@@ -106,7 +106,7 @@ ioWrite(IoWrite *this, const Buffer *buffer)
|
||||
ASSERT(this->opened && !this->closed);
|
||||
|
||||
// Only write if there is data to write
|
||||
if (buffer != NULL && bufUsed(buffer) > 0)
|
||||
if (buffer != NULL && !bufEmpty(buffer))
|
||||
{
|
||||
do
|
||||
{
|
||||
@@ -209,7 +209,7 @@ ioWriteFlush(IoWrite *this)
|
||||
ASSERT(this->opened && !this->closed);
|
||||
ASSERT(!this->filterGroupSet);
|
||||
|
||||
if (bufUsed(this->output) > 0)
|
||||
if (!bufEmpty(this->output))
|
||||
{
|
||||
this->interface.write(this->driver, this->output);
|
||||
bufUsedZero(this->output);
|
||||
@@ -235,7 +235,7 @@ ioWriteClose(IoWrite *this)
|
||||
ioFilterGroupProcess(this->filterGroup, NULL, this->output);
|
||||
|
||||
// Write data if the buffer is full or if this is the last buffer to be written
|
||||
if (bufRemains(this->output) == 0 || (ioFilterGroupDone(this->filterGroup) && bufUsed(this->output) > 0))
|
||||
if (bufRemains(this->output) == 0 || (ioFilterGroupDone(this->filterGroup) && !bufEmpty(this->output)))
|
||||
{
|
||||
this->interface.write(this->driver, this->output);
|
||||
bufUsedZero(this->output);
|
||||
|
@@ -102,6 +102,13 @@ void bufUsedInc(Buffer *this, size_t inc);
|
||||
void bufUsedSet(Buffer *this, size_t used);
|
||||
void bufUsedZero(Buffer *this);
|
||||
|
||||
// Is the buffer empty?
|
||||
__attribute__((always_inline)) static inline bool
|
||||
bufEmpty(const Buffer *this)
|
||||
{
|
||||
return bufUsed(this) == 0;
|
||||
}
|
||||
|
||||
// Remaining space in the buffer
|
||||
__attribute__((always_inline)) static inline size_t
|
||||
bufRemains(const Buffer *this)
|
||||
|
@@ -1055,7 +1055,7 @@ pckWriteBuffer(PackWrite *this, const Buffer *buffer)
|
||||
else
|
||||
{
|
||||
// Flush the internal buffer if it has data
|
||||
if (bufUsed(this->buffer) > 0)
|
||||
if (!bufEmpty(this->buffer))
|
||||
{
|
||||
ioWrite(this->write, this->buffer);
|
||||
bufUsedZero(this->buffer);
|
||||
@@ -1322,10 +1322,10 @@ pckWriteBin(PackWrite *this, const Buffer *value, PckWriteBinParam param)
|
||||
ASSERT(value != NULL);
|
||||
|
||||
// Write buffer size if > 0
|
||||
pckWriteTag(this, pckTypeBin, param.id, bufUsed(value) > 0);
|
||||
pckWriteTag(this, pckTypeBin, param.id, !bufEmpty(value));
|
||||
|
||||
// Write buffer data if size > 0
|
||||
if (bufUsed(value) > 0)
|
||||
if (!bufEmpty(value))
|
||||
{
|
||||
pckWriteUInt64Internal(this, bufUsed(value));
|
||||
pckWriteBuffer(this, value);
|
||||
@@ -1562,7 +1562,7 @@ pckWriteEnd(PackWrite *this)
|
||||
// If writing to io flush the internal buffer
|
||||
if (this->write != NULL)
|
||||
{
|
||||
if (bufUsed(this->buffer) > 0)
|
||||
if (!bufEmpty(this->buffer))
|
||||
ioWrite(this->write, this->buffer);
|
||||
}
|
||||
// Else resize the external buffer to trim off extra space added during processing
|
||||
|
@@ -451,7 +451,7 @@ xmlDocumentNewBuf(const Buffer *buffer)
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
ASSERT(buffer != NULL);
|
||||
ASSERT(bufUsed(buffer) > 0);
|
||||
ASSERT(!bufEmpty(buffer));
|
||||
|
||||
FUNCTION_TEST_RETURN(xmlDocumentNewC(bufPtrConst(buffer), bufUsed(buffer)));
|
||||
}
|
||||
|
@@ -224,7 +224,7 @@ storageAzureRequestAsync(StorageAzure *this, const String *verb, StorageAzureReq
|
||||
// Set content length
|
||||
httpHeaderAdd(
|
||||
requestHeader, HTTP_HEADER_CONTENT_LENGTH_STR,
|
||||
param.content == NULL || bufUsed(param.content) == 0 ? ZERO_STR : strNewFmt("%zu", bufUsed(param.content)));
|
||||
param.content == NULL || bufEmpty(param.content) ? ZERO_STR : strNewFmt("%zu", bufUsed(param.content)));
|
||||
|
||||
// Calculate content-md5 header if there is content
|
||||
if (param.content != NULL)
|
||||
|
@@ -221,7 +221,7 @@ storageWriteAzureClose(THIS_VOID)
|
||||
if (this->blockIdList != NULL)
|
||||
{
|
||||
// If there is anything left in the block buffer then write it
|
||||
if (bufUsed(this->blockBuffer) > 0)
|
||||
if (!bufEmpty(this->blockBuffer))
|
||||
storageWriteAzureBlockAsync(this);
|
||||
|
||||
// Complete prior async request, if any
|
||||
|
@@ -214,7 +214,7 @@ storageRemoteProtocol(const String *command, const VariantList *paramList, Proto
|
||||
{
|
||||
ioRead(fileRead, buffer);
|
||||
|
||||
if (bufUsed(buffer) > 0)
|
||||
if (!bufEmpty(buffer))
|
||||
{
|
||||
ioWriteStrLine(protocolServerIoWrite(server), strNewFmt(PROTOCOL_BLOCK_HEADER "%zu", bufUsed(buffer)));
|
||||
ioWrite(protocolServerIoWrite(server), buffer);
|
||||
|
@@ -301,7 +301,7 @@ storageS3RequestAsync(StorageS3 *this, const String *verb, const String *uri, St
|
||||
// Set content length
|
||||
httpHeaderAdd(
|
||||
requestHeader, HTTP_HEADER_CONTENT_LENGTH_STR,
|
||||
param.content == NULL || bufUsed(param.content) == 0 ? ZERO_STR : strNewFmt("%zu", bufUsed(param.content)));
|
||||
param.content == NULL || bufEmpty(param.content) ? ZERO_STR : strNewFmt("%zu", bufUsed(param.content)));
|
||||
|
||||
// Calculate content-md5 header if there is content
|
||||
if (param.content != NULL)
|
||||
@@ -410,7 +410,7 @@ storageS3RequestAsync(StorageS3 *this, const String *verb, const String *uri, St
|
||||
// Generate authorization header
|
||||
storageS3Auth(
|
||||
this, verb, httpUriEncode(uri, true), param.query, storageS3DateTime(time(NULL)), requestHeader,
|
||||
param.content == NULL || bufUsed(param.content) == 0 ?
|
||||
param.content == NULL || bufEmpty(param.content) ?
|
||||
HASH_TYPE_SHA256_ZERO_STR : bufHex(cryptoHashOne(HASH_TYPE_SHA256_STR, param.content)));
|
||||
|
||||
// Send request
|
||||
@@ -804,7 +804,7 @@ storageS3PathRemoveInternal(StorageS3 *this, HttpRequest *request, XmlDocument *
|
||||
const Buffer *response = httpResponseContent(storageS3ResponseP(request));
|
||||
|
||||
// Nothing is returned when there are no errors
|
||||
if (bufUsed(response) > 0)
|
||||
if (!bufEmpty(response))
|
||||
{
|
||||
XmlNodeList *errorList = xmlNodeChildList(xmlDocumentRoot(xmlDocumentNewBuf(response)), S3_XML_TAG_ERROR_STR);
|
||||
|
||||
|
@@ -219,7 +219,7 @@ storageWriteS3Close(THIS_VOID)
|
||||
if (this->uploadId != NULL)
|
||||
{
|
||||
// If there is anything left in the part buffer then write it
|
||||
if (bufUsed(this->partBuffer) > 0)
|
||||
if (!bufEmpty(this->partBuffer))
|
||||
storageWriteS3PartAsync(this);
|
||||
|
||||
// Complete prior async request, if any
|
||||
|
@@ -385,7 +385,7 @@ void hrnServerRun(IoRead *read, HrnServerProtocol protocol, HrnServerRunParam pa
|
||||
CATCH(FileReadError)
|
||||
{
|
||||
// If nothing was read then throw the original error
|
||||
if (bufUsed(buffer) == 0)
|
||||
if (bufEmpty(buffer))
|
||||
THROW_FMT(AssertError, "server expected '%s' but got EOF", strZ(expected));
|
||||
}
|
||||
TRY_END();
|
||||
|
@@ -234,7 +234,7 @@ const char *
|
||||
hrnStoragePutLog(const Storage *storage, const char *file, const Buffer *buffer, HrnStoragePutParam param)
|
||||
{
|
||||
// Empty if buffer is NULL
|
||||
String *log = strNew(buffer == NULL || bufUsed(buffer) == 0 ? "(empty) " : "");
|
||||
String *log = strNew(buffer == NULL || bufEmpty(buffer) ? "(empty) " : "");
|
||||
|
||||
// Add compression detail
|
||||
if (param.compressType != compressTypeNone)
|
||||
|
Reference in New Issue
Block a user