You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-11-06 08:49:29 +02:00
Fix storageReadRemote() to return actual read bytes.
All storage interface read methods should return actual read bytes. This patch refactors storageReadRemote() to eliminate duplicated code and return actual read bytes. The return value is calculated as the number of bytes written to the passed buffer. This is technically a bug but does not express as an issue currently because this return value is not being used. It will be used in the future, though, so it needs to be fixed.
This commit is contained in:
@@ -154,22 +154,20 @@ storageReadRemote(THIS_VOID, Buffer *buffer, bool block)
|
||||
// Read if not eof
|
||||
if (!this->eof)
|
||||
{
|
||||
// If the buffer can contain all remaining bytes
|
||||
if (bufRemains(buffer) >= this->remaining)
|
||||
{
|
||||
bufCatSub(buffer, this->block, bufUsed(this->block) - this->remaining, this->remaining);
|
||||
// Copy as much as possible into the output buffer
|
||||
const size_t remains = this->remaining < bufRemains(buffer) ? this->remaining : bufRemains(buffer);
|
||||
|
||||
this->remaining = 0;
|
||||
bufCatSub(buffer, this->block, bufUsed(this->block) - this->remaining, remains);
|
||||
|
||||
result += remains;
|
||||
this->remaining -= remains;
|
||||
|
||||
// If there is no more to copy from the block buffer then free it
|
||||
if (this->remaining == 0)
|
||||
{
|
||||
bufFree(this->block);
|
||||
this->block = NULL;
|
||||
}
|
||||
// Else read what we can
|
||||
else
|
||||
{
|
||||
size_t remains = bufRemains(buffer);
|
||||
bufCatSub(buffer, this->block, bufUsed(this->block) - this->remaining, remains);
|
||||
this->remaining -= remains;
|
||||
}
|
||||
}
|
||||
}
|
||||
while (!this->eof && !bufFull(buffer));
|
||||
|
||||
@@ -264,6 +264,24 @@ testRun(void)
|
||||
strZ(strNewBuf(storageGetP(storageNewReadP(storagePgWrite, STRDEF("test.txt"))))), FileMissingError,
|
||||
"raised from remote-0 shim protocol: " STORAGE_ERROR_READ_MISSING, TEST_PATH "/pg256/test.txt");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("raw read file without compression");
|
||||
|
||||
HRN_STORAGE_PUT(storageTest, TEST_PATH "/repo128/test.txt", contentBuf);
|
||||
|
||||
// Disable protocol compression in the storage object
|
||||
((StorageRemote *)storageDriver(storageRepo))->compressLevel = 0;
|
||||
|
||||
Buffer *buffer = bufNew(bufUsed(contentBuf));
|
||||
size_t size;
|
||||
StorageRead *fileReadRaw;
|
||||
TEST_ASSIGN(fileReadRaw, storageNewReadP(storageRepo, STRDEF("test.txt")), "new file");
|
||||
TEST_RESULT_BOOL(ioReadOpen(storageReadIo(fileReadRaw)), true, "open read");
|
||||
TEST_ASSIGN(size, storageReadRemote(fileReadRaw->driver, buffer, true), "read file and save returned size");
|
||||
TEST_RESULT_UINT(size, bufUsed(buffer), "check returned size");
|
||||
TEST_RESULT_UINT(size, bufUsed(contentBuf), "returned size should be the same as the file size");
|
||||
TEST_RESULT_VOID(ioReadClose(storageReadIo(fileReadRaw)), "close");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("read file without compression");
|
||||
|
||||
@@ -295,7 +313,7 @@ testRun(void)
|
||||
|
||||
size_t bufferOld = ioBufferSize();
|
||||
ioBufferSizeSet(11);
|
||||
Buffer *buffer = bufNew(11);
|
||||
buffer = bufNew(11);
|
||||
|
||||
TEST_ASSIGN(fileRead, storageNewReadP(storageRepo, STRDEF("test.txt"), .limit = VARUINT64(11)), "get file");
|
||||
TEST_RESULT_BOOL(ioReadOpen(storageReadIo(fileRead)), true, "open read");
|
||||
|
||||
Reference in New Issue
Block a user