diff --git a/src/command/archive/get/get.c b/src/command/archive/get/get.c index cc93213066..6ccf89dead 100644 --- a/src/command/archive/get/get.c +++ b/src/command/archive/get/get.c @@ -27,7 +27,7 @@ Archive Get Command #include "protocol/helper.h" #include "protocol/parallel.h" #include "storage/helper.h" -#include "storage/write.intern.h" +#include "storage/write.h" /*********************************************************************************************************************************** Constants for log messages that are used multiple times to keep them consistent diff --git a/src/command/archive/get/protocol.c b/src/command/archive/get/protocol.c index 8caa078e1c..f7fc04bc03 100644 --- a/src/command/archive/get/protocol.c +++ b/src/command/archive/get/protocol.c @@ -11,7 +11,7 @@ Archive Get Protocol Handler #include "common/memContext.h" #include "config/config.h" #include "storage/helper.h" -#include "storage/write.intern.h" +#include "storage/write.h" /**********************************************************************************************************************************/ FN_EXTERN ProtocolServerResult * diff --git a/src/command/restore/restore.c b/src/command/restore/restore.c index fddfc28e08..5d85b7f6e7 100644 --- a/src/command/restore/restore.c +++ b/src/command/restore/restore.c @@ -25,7 +25,7 @@ Restore Command #include "protocol/helper.h" #include "protocol/parallel.h" #include "storage/helper.h" -#include "storage/write.intern.h" +#include "storage/write.h" #include "version.h" /*********************************************************************************************************************************** diff --git a/src/common/io/read.c b/src/common/io/read.c index be9a9326d0..dc0a59b48b 100644 --- a/src/common/io/read.c +++ b/src/common/io/read.c @@ -64,7 +64,7 @@ ioReadOpen(IoRead *const this) ASSERT(ioFilterGroupSize(this->pub.filterGroup) == 0 || !ioReadBlock(this)); // Open if the driver has an open function - const bool result = this->pub.interface.open != NULL ? this->pub.interface.open(this->pub.driver) : true; + const bool result = ioReadInterface(this)->open != NULL ? ioReadInterface(this)->open(ioReadDriver(this)) : true; // Only open the filter group if the read was opened if (result) @@ -92,7 +92,7 @@ ioReadEofDriver(const IoRead *const this) ASSERT(this != NULL); ASSERT(this->pub.opened && !this->pub.closed); - FUNCTION_LOG_RETURN(BOOL, this->pub.interface.eof != NULL ? this->pub.interface.eof(this->pub.driver) : false); + FUNCTION_LOG_RETURN(BOOL, ioReadInterface(this)->eof != NULL ? ioReadInterface(this)->eof(ioReadDriver(this)) : false); } /**********************************************************************************************************************************/ @@ -133,7 +133,7 @@ ioReadInternal(IoRead *const this, Buffer *const buffer, const bool block) if (ioReadBlock(this) && bufRemains(this->input) > bufRemains(buffer)) bufLimitSet(this->input, bufRemains(buffer)); - this->pub.interface.read(this->pub.driver, this->input, block); + ioReadInterface(this)->read(ioReadDriver(this), this->input, block); bufLimitClear(this->input); } // Set input to NULL and flush (no need to actually free the buffer here as it will be freed with the mem context) @@ -421,8 +421,8 @@ ioReadReady(IoRead *const this, const IoReadReadyParam param) bool result = true; - if (this->pub.interface.ready != NULL) - result = this->pub.interface.ready(this->pub.driver, param.error); + if (ioReadInterface(this)->ready != NULL) + result = ioReadInterface(this)->ready(ioReadDriver(this), param.error); FUNCTION_LOG_RETURN(BOOL, result); } @@ -478,8 +478,8 @@ ioReadClose(IoRead *const this) ioFilterGroupClose(this->pub.filterGroup); // Close the driver if there is a close function - if (this->pub.interface.close != NULL) - this->pub.interface.close(this->pub.driver); + if (ioReadInterface(this)->close != NULL) + ioReadInterface(this)->close(ioReadDriver(this)); #ifdef DEBUG this->pub.closed = true; @@ -498,5 +498,5 @@ ioReadFd(const IoRead *const this) ASSERT(this != NULL); - FUNCTION_LOG_RETURN(INT, this->pub.interface.fd == NULL ? -1 : this->pub.interface.fd(this->pub.driver)); + FUNCTION_LOG_RETURN(INT, ioReadInterface(this)->fd == NULL ? -1 : ioReadInterface(this)->fd(ioReadDriver(this))); } diff --git a/src/common/io/read.intern.h b/src/common/io/read.intern.h index d4539d91e3..3a1b4b6b35 100644 --- a/src/common/io/read.intern.h +++ b/src/common/io/read.intern.h @@ -50,7 +50,7 @@ typedef struct IoReadPub // Driver for the read object FN_INLINE_ALWAYS void * -ioReadDriver(IoRead *const this) +ioReadDriver(const IoRead *const this) { return THIS_PUB(IoRead)->driver; } diff --git a/src/common/io/write.c b/src/common/io/write.c index 350ff36105..6a700205a8 100644 --- a/src/common/io/write.c +++ b/src/common/io/write.c @@ -16,8 +16,6 @@ Object type struct IoWrite { IoWritePub pub; // Publicly accessible variables - void *driver; // Driver object - IoWriteInterface interface; // Driver interface Buffer *output; // Output buffer #ifdef DEBUG @@ -45,10 +43,10 @@ ioWriteNew(void *const driver, const IoWriteInterface interface) { .pub = { + .driver = objMoveToInterface(driver, this, memContextPrior()), + .interface = interface, .filterGroup = ioFilterGroupNew(), }, - .driver = objMoveToInterface(driver, this, memContextPrior()), - .interface = interface, .output = bufNew(ioBufferSize()), }; } @@ -68,8 +66,8 @@ ioWriteOpen(IoWrite *const this) ASSERT(this != NULL); ASSERT(!this->opened && !this->closed); - if (this->interface.open != NULL) - this->interface.open(this->driver); + if (ioWriteInterface(this)->open != NULL) + ioWriteInterface(this)->open(ioWriteDriver(this)); // Track whether filters were added to prevent flush() from being called later since flush() won't work with most filters #ifdef DEBUG @@ -108,7 +106,7 @@ ioWrite(IoWrite *const this, const Buffer *const buffer) // Write data if the buffer is full if (bufRemains(this->output) == 0) { - this->interface.write(this->driver, this->output); + ioWriteInterface(this)->write(ioWriteDriver(this), this->output); bufUsedZero(this->output); } } @@ -149,8 +147,8 @@ ioWriteReady(IoWrite *const this, const IoWriteReadyParam param) bool result = true; - if (this->interface.ready != NULL) - result = this->interface.ready(this->driver, param.error); + if (ioWriteInterface(this)->ready != NULL) + result = ioWriteInterface(this)->ready(ioWriteDriver(this), param.error); FUNCTION_LOG_RETURN(BOOL, result); } @@ -224,7 +222,7 @@ ioWriteFlush(IoWrite *const this) if (!bufEmpty(this->output)) { - this->interface.write(this->driver, this->output); + ioWriteInterface(this)->write(ioWriteDriver(this), this->output); bufUsedZero(this->output); } @@ -250,7 +248,7 @@ ioWriteClose(IoWrite *const this) // Write data if the buffer is full or if this is the last buffer to be written if (bufRemains(this->output) == 0 || (ioFilterGroupDone(this->pub.filterGroup) && !bufEmpty(this->output))) { - this->interface.write(this->driver, this->output); + ioWriteInterface(this)->write(ioWriteDriver(this), this->output); bufUsedZero(this->output); } } @@ -260,8 +258,8 @@ ioWriteClose(IoWrite *const this) ioFilterGroupClose(this->pub.filterGroup); // Close the driver if there is a close function - if (this->interface.close != NULL) - this->interface.close(this->driver); + if (ioWriteInterface(this)->close != NULL) + ioWriteInterface(this)->close(ioWriteDriver(this)); #ifdef DEBUG this->closed = true; @@ -280,5 +278,5 @@ ioWriteFd(const IoWrite *const this) ASSERT(this != NULL); - FUNCTION_LOG_RETURN(INT, this->interface.fd == NULL ? -1 : this->interface.fd(this->driver)); + FUNCTION_LOG_RETURN(INT, ioWriteInterface(this)->fd == NULL ? -1 : ioWriteInterface(this)->fd(ioWriteDriver(this))); } diff --git a/src/common/io/write.h b/src/common/io/write.h index f305461a3e..69ba2e994e 100644 --- a/src/common/io/write.h +++ b/src/common/io/write.h @@ -21,11 +21,6 @@ typedef struct IoWrite IoWrite; /*********************************************************************************************************************************** Getters/Setters ***********************************************************************************************************************************/ -typedef struct IoWritePub -{ - IoFilterGroup *filterGroup; // IO filters -} IoWritePub; - // Filter group. Filters must be set before open and cannot be reset FN_INLINE_ALWAYS IoFilterGroup * ioWriteFilterGroup(IoWrite *const this) diff --git a/src/common/io/write.intern.h b/src/common/io/write.intern.h index 4bdb28fb90..c1b270e18b 100644 --- a/src/common/io/write.intern.h +++ b/src/common/io/write.intern.h @@ -28,6 +28,30 @@ typedef struct IoWriteInterface FN_EXTERN IoWrite *ioWriteNew(void *driver, IoWriteInterface interface); +/*********************************************************************************************************************************** +Getters/Setters +***********************************************************************************************************************************/ +typedef struct IoWritePub +{ + void *driver; // Driver object + IoWriteInterface interface; // Driver interface + IoFilterGroup *filterGroup; // IO filters +} IoWritePub; + +// Driver for the write object +FN_INLINE_ALWAYS void * +ioWriteDriver(const IoWrite *const this) +{ + return THIS_PUB(IoWrite)->driver; +} + +// Interface for the write object +FN_INLINE_ALWAYS const IoWriteInterface * +ioWriteInterface(const IoWrite *const this) +{ + return &THIS_PUB(IoWrite)->interface; +} + /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ diff --git a/src/storage/azure/read.c b/src/storage/azure/read.c index 2199084849..17027095ba 100644 --- a/src/storage/azure/read.c +++ b/src/storage/azure/read.c @@ -8,7 +8,7 @@ Azure Storage Read #include "common/log.h" #include "common/type/object.h" #include "storage/azure/read.h" -#include "storage/read.intern.h" +#include "storage/read.h" /*********************************************************************************************************************************** Object type diff --git a/src/storage/azure/write.c b/src/storage/azure/write.c index 37984a71e6..94b9b3a2ac 100644 --- a/src/storage/azure/write.c +++ b/src/storage/azure/write.c @@ -10,7 +10,7 @@ Azure Storage File Write #include "common/type/object.h" #include "common/type/xml.h" #include "storage/azure/write.h" -#include "storage/write.intern.h" +#include "storage/write.h" /*********************************************************************************************************************************** Azure HTTP headers diff --git a/src/storage/gcs/read.c b/src/storage/gcs/read.c index ffdf6bbabd..68fc36e420 100644 --- a/src/storage/gcs/read.c +++ b/src/storage/gcs/read.c @@ -9,7 +9,7 @@ GCS Storage Read #include "common/log.h" #include "common/type/object.h" #include "storage/gcs/read.h" -#include "storage/read.intern.h" +#include "storage/read.h" /*********************************************************************************************************************************** GCS query tokens diff --git a/src/storage/gcs/write.c b/src/storage/gcs/write.c index f5d54a9157..11a98ebd04 100644 --- a/src/storage/gcs/write.c +++ b/src/storage/gcs/write.c @@ -11,7 +11,7 @@ GCS Storage File Write #include "common/type/keyValue.h" #include "common/type/object.h" #include "storage/gcs/write.h" -#include "storage/write.intern.h" +#include "storage/write.h" /*********************************************************************************************************************************** GCS query tokens diff --git a/src/storage/posix/read.c b/src/storage/posix/read.c index c1b54af877..3bab37f04c 100644 --- a/src/storage/posix/read.c +++ b/src/storage/posix/read.c @@ -11,7 +11,7 @@ Posix Storage Read #include "common/log.h" #include "common/type/object.h" #include "storage/posix/read.h" -#include "storage/read.intern.h" +#include "storage/read.h" /*********************************************************************************************************************************** Object types diff --git a/src/storage/posix/write.c b/src/storage/posix/write.c index f30f2a0876..b6dc205bf8 100644 --- a/src/storage/posix/write.c +++ b/src/storage/posix/write.c @@ -14,7 +14,7 @@ Posix Storage File write #include "common/type/object.h" #include "common/user.h" #include "storage/posix/write.h" -#include "storage/write.intern.h" +#include "storage/write.h" /*********************************************************************************************************************************** Object type diff --git a/src/storage/read.c b/src/storage/read.c index 0cca899f85..c17e50f293 100644 --- a/src/storage/read.c +++ b/src/storage/read.c @@ -14,7 +14,6 @@ Object type struct StorageRead { StorageReadPub pub; // Publicly accessible variables - void *driver; // Driver }; /*********************************************************************************************************************************** @@ -48,7 +47,6 @@ storageReadNew(void *const driver, const StorageReadInterface *const interface) .interface = interface, .io = ioReadNew(driver, interface->ioInterface), }, - .driver = objMoveToInterface(driver, this, memContextPrior()), }; } OBJ_NEW_END(); diff --git a/src/storage/read.h b/src/storage/read.h index 1d74ea8cfb..e47dc49b51 100644 --- a/src/storage/read.h +++ b/src/storage/read.h @@ -26,17 +26,11 @@ storageReadMove(StorageRead *const this, MemContext *const parentNew) /*********************************************************************************************************************************** Getters/Setters ***********************************************************************************************************************************/ -typedef struct StorageReadPub -{ - const StorageReadInterface *interface; // File data (name, driver type, etc.) - IoRead *io; // Read interface -} StorageReadPub; - // Should a missing file be ignored? FN_INLINE_ALWAYS bool storageReadIgnoreMissing(const StorageRead *const this) { - return THIS_PUB(StorageRead)->interface->ignoreMissing; + return storageReadInterface(this)->ignoreMissing; } // Read interface @@ -50,28 +44,28 @@ storageReadIo(const StorageRead *const this) FN_INLINE_ALWAYS const Variant * storageReadLimit(const StorageRead *const this) { - return THIS_PUB(StorageRead)->interface->limit; + return storageReadInterface(this)->limit; } // File name FN_INLINE_ALWAYS const String * storageReadName(const StorageRead *const this) { - return THIS_PUB(StorageRead)->interface->name; + return storageReadInterface(this)->name; } // Is there a read limit? NULL for no limit. FN_INLINE_ALWAYS uint64_t storageReadOffset(const StorageRead *const this) { - return THIS_PUB(StorageRead)->interface->offset; + return storageReadInterface(this)->offset; } // Get file type FN_INLINE_ALWAYS StringId storageReadType(const StorageRead *const this) { - return THIS_PUB(StorageRead)->interface->type; + return storageReadInterface(this)->type; } /*********************************************************************************************************************************** diff --git a/src/storage/read.intern.h b/src/storage/read.intern.h index 6377c119d8..3a51af2998 100644 --- a/src/storage/read.intern.h +++ b/src/storage/read.intern.h @@ -18,11 +18,27 @@ typedef struct StorageReadInterface bool ignoreMissing; uint64_t offset; // Where to start reading in the file const Variant *limit; // Limit how many bytes are read (NULL for no limit) + bool version; // Read version + const String *versionId; // File version to read IoReadInterface ioInterface; } StorageReadInterface; -#include "storage/read.h" - FN_EXTERN StorageRead *storageReadNew(void *driver, const StorageReadInterface *interface); +/*********************************************************************************************************************************** +Getters/Setters +***********************************************************************************************************************************/ +typedef struct StorageReadPub +{ + const StorageReadInterface *interface; // File data (name, driver type, etc.) + IoRead *io; // Read interface +} StorageReadPub; + +// Read interface +FN_INLINE_ALWAYS const StorageReadInterface * +storageReadInterface(const StorageRead *const this) +{ + return THIS_PUB(StorageRead)->interface; +} + #endif diff --git a/src/storage/remote/read.c b/src/storage/remote/read.c index ee7a75ce72..a509dfd9ee 100644 --- a/src/storage/remote/read.c +++ b/src/storage/remote/read.c @@ -13,7 +13,7 @@ Remote Storage Read #include "common/log.h" #include "common/type/convert.h" #include "common/type/object.h" -#include "storage/read.intern.h" +#include "storage/read.h" #include "storage/remote/protocol.h" #include "storage/remote/read.h" diff --git a/src/storage/remote/write.c b/src/storage/remote/write.c index f66dca305e..6d740eb540 100644 --- a/src/storage/remote/write.c +++ b/src/storage/remote/write.c @@ -11,7 +11,7 @@ Remote Storage File write #include "common/type/object.h" #include "storage/remote/protocol.h" #include "storage/remote/write.h" -#include "storage/write.intern.h" +#include "storage/write.h" /*********************************************************************************************************************************** Object type diff --git a/src/storage/s3/read.c b/src/storage/s3/read.c index 3301b78639..f061265ae3 100644 --- a/src/storage/s3/read.c +++ b/src/storage/s3/read.c @@ -7,7 +7,7 @@ S3 Storage Read #include "common/io/http/client.h" #include "common/log.h" #include "common/type/object.h" -#include "storage/read.intern.h" +#include "storage/read.h" #include "storage/s3/read.h" /*********************************************************************************************************************************** diff --git a/src/storage/s3/write.c b/src/storage/s3/write.c index 63b002ec78..454eb6f9bf 100644 --- a/src/storage/s3/write.c +++ b/src/storage/s3/write.c @@ -8,7 +8,7 @@ S3 Storage File Write #include "common/type/object.h" #include "common/type/xml.h" #include "storage/s3/write.h" -#include "storage/write.intern.h" +#include "storage/write.h" /*********************************************************************************************************************************** S3 query tokens diff --git a/src/storage/sftp/read.c b/src/storage/sftp/read.c index 843a50c805..cab8a6a589 100644 --- a/src/storage/sftp/read.c +++ b/src/storage/sftp/read.c @@ -8,7 +8,7 @@ SFTP Storage Read #include "common/debug.h" #include "common/io/session.h" #include "common/log.h" -#include "storage/read.intern.h" +#include "storage/read.h" #include "storage/sftp/read.h" /*********************************************************************************************************************************** diff --git a/src/storage/sftp/write.c b/src/storage/sftp/write.c index 528bf1479f..a74fbb8d3d 100644 --- a/src/storage/sftp/write.c +++ b/src/storage/sftp/write.c @@ -9,7 +9,7 @@ SFTP Storage File Write #include "common/log.h" #include "common/user.h" #include "storage/sftp/write.h" -#include "storage/write.intern.h" +#include "storage/write.h" /*********************************************************************************************************************************** Object type diff --git a/src/storage/write.c b/src/storage/write.c index ff907f156c..9d018efaa1 100644 --- a/src/storage/write.c +++ b/src/storage/write.c @@ -14,7 +14,6 @@ Object type struct StorageWrite { StorageWritePub pub; // Publicly accessible variables - void *driver; // Driver }; /*********************************************************************************************************************************** @@ -51,7 +50,6 @@ storageWriteNew(void *const driver, const StorageWriteInterface *const interface .interface = interface, .io = ioWriteNew(driver, interface->ioInterface), }, - .driver = objMoveToInterface(driver, this, memContextPrior()), }; } OBJ_NEW_END(); diff --git a/src/storage/write.h b/src/storage/write.h index 3dc49ddefb..528cebab9c 100644 --- a/src/storage/write.h +++ b/src/storage/write.h @@ -29,25 +29,19 @@ storageWriteMove(StorageWrite *const this, MemContext *const parentNew) /*********************************************************************************************************************************** Getters/Setters ***********************************************************************************************************************************/ -typedef struct StorageWritePub -{ - const StorageWriteInterface *interface; // File data (name, driver type, etc.) - IoWrite *io; // Write interface -} StorageWritePub; - // Will the file be written atomically? Atomic writes means the file will be complete or be missing. Filesystems have different ways // to accomplish this. FN_INLINE_ALWAYS bool storageWriteAtomic(const StorageWrite *const this) { - return THIS_PUB(StorageWrite)->interface->atomic; + return storageWriteInterface(this)->atomic; } // Will the path be created if required? FN_INLINE_ALWAYS bool storageWriteCreatePath(const StorageWrite *const this) { - return THIS_PUB(StorageWrite)->interface->createPath; + return storageWriteInterface(this)->createPath; } // Write interface @@ -61,49 +55,49 @@ storageWriteIo(const StorageWrite *const this) FN_INLINE_ALWAYS mode_t storageWriteModeFile(const StorageWrite *const this) { - return THIS_PUB(StorageWrite)->interface->modeFile; + return storageWriteInterface(this)->modeFile; } // Path mode (if the destination path needs to be create) FN_INLINE_ALWAYS mode_t storageWriteModePath(const StorageWrite *const this) { - return THIS_PUB(StorageWrite)->interface->modePath; + return storageWriteInterface(this)->modePath; } // File name FN_INLINE_ALWAYS const String * storageWriteName(const StorageWrite *const this) { - return THIS_PUB(StorageWrite)->interface->name; + return storageWriteInterface(this)->name; } // Will the file be synced before it is closed? FN_INLINE_ALWAYS bool storageWriteSyncFile(const StorageWrite *const this) { - return THIS_PUB(StorageWrite)->interface->syncFile; + return storageWriteInterface(this)->syncFile; } // Will the path be synced after the file is closed? FN_INLINE_ALWAYS bool storageWriteSyncPath(const StorageWrite *const this) { - return THIS_PUB(StorageWrite)->interface->syncPath; + return storageWriteInterface(this)->syncPath; } // Will the file be truncated if it exists? FN_INLINE_ALWAYS bool storageWriteTruncate(const StorageWrite *const this) { - return THIS_PUB(StorageWrite)->interface->truncate; + return storageWriteInterface(this)->truncate; } // File type FN_INLINE_ALWAYS StringId storageWriteType(const StorageWrite *const this) { - return THIS_PUB(StorageWrite)->interface->type; + return storageWriteInterface(this)->type; } /*********************************************************************************************************************************** diff --git a/src/storage/write.intern.h b/src/storage/write.intern.h index 566c738431..6e205a0e9f 100644 --- a/src/storage/write.intern.h +++ b/src/storage/write.intern.h @@ -38,4 +38,20 @@ typedef struct StorageWriteInterface FN_EXTERN StorageWrite *storageWriteNew(void *driver, const StorageWriteInterface *interface); +/*********************************************************************************************************************************** +Getters/Setters +***********************************************************************************************************************************/ +typedef struct StorageWritePub +{ + const StorageWriteInterface *interface; // File data (name, driver type, etc.) + IoWrite *io; // Write interface +} StorageWritePub; + +// Write interface +FN_INLINE_ALWAYS const StorageWriteInterface * +storageWriteInterface(const StorageWrite *const this) +{ + return THIS_PUB(StorageWrite)->interface; +} + #endif diff --git a/test/src/module/common/ioTest.c b/test/src/module/common/ioTest.c index 656dc8db70..9356bd3dbd 100644 --- a/test/src/module/common/ioTest.c +++ b/test/src/module/common/ioTest.c @@ -654,7 +654,7 @@ testRun(void) TEST_ASSIGN(write, ioFdWriteNewOpen(STRDEF("write test"), HRN_FORK_CHILD_WRITE_FD(), 1000), "move write"); TEST_RESULT_BOOL(ioWriteReadyP(write), true, "write is ready"); - TEST_RESULT_INT(ioWriteFd(write), ((IoFdWrite *)write->driver)->fd, "check write fd"); + TEST_RESULT_INT(ioWriteFd(write), ((IoFdWrite *)ioWriteDriver(write))->fd, "check write fd"); // Write a line to be read TEST_RESULT_VOID(ioWriteStrLine(write, STRDEF("test string 1")), "write test string"); diff --git a/test/src/module/storage/azureTest.c b/test/src/module/storage/azureTest.c index 43aa2cea9f..b5e1b45ded 100644 --- a/test/src/module/storage/azureTest.c +++ b/test/src/module/storage/azureTest.c @@ -612,7 +612,7 @@ testRun(void) TEST_RESULT_BOOL(storageWriteSyncPath(write), true, "path is synced"); TEST_RESULT_BOOL(storageWriteTruncate(write), true, "file will be truncated"); - TEST_RESULT_VOID(storageWriteAzureClose(write->driver), "close file again"); + TEST_RESULT_VOID(storageWriteAzureClose(ioWriteDriver(storageWriteIo(write))), "close file again"); // ----------------------------------------------------------------------------------------------------------------- TEST_TITLE("write zero-length file"); diff --git a/test/src/module/storage/gcsTest.c b/test/src/module/storage/gcsTest.c index 00dbaa0e0c..29df9f4375 100644 --- a/test/src/module/storage/gcsTest.c +++ b/test/src/module/storage/gcsTest.c @@ -568,7 +568,7 @@ testRun(void) TEST_RESULT_BOOL(storageWriteSyncPath(write), true, "path is synced"); TEST_RESULT_BOOL(storageWriteTruncate(write), true, "file will be truncated"); - TEST_RESULT_VOID(storageWriteGcsClose(write->driver), "close file again"); + TEST_RESULT_VOID(storageWriteGcsClose(ioWriteDriver(storageWriteIo(write))), "close file again"); // ----------------------------------------------------------------------------------------------------------------- TEST_TITLE("write zero-length file"); diff --git a/test/src/module/storage/posixTest.c b/test/src/module/storage/posixTest.c index d7fd6b1fcc..e20e6e4886 100644 --- a/test/src/module/storage/posixTest.c +++ b/test/src/module/storage/posixTest.c @@ -946,7 +946,8 @@ testRun(void) HRN_SYSTEM_FMT("touch %s", strZ(fileName)); TEST_RESULT_BOOL(ioReadOpen(storageReadIo(file)), true, "open file"); - TEST_RESULT_INT(ioReadFd(storageReadIo(file)), ((StorageReadPosix *)file->driver)->fd, "check read fd"); + TEST_RESULT_INT( + ioReadFd(storageReadIo(file)), ((StorageReadPosix *)ioReadDriver(storageReadIo(file)))->fd, "check read fd"); TEST_RESULT_VOID(ioReadClose(storageReadIo(file)), "close file"); } @@ -976,7 +977,8 @@ testRun(void) storageNewWriteP(storageTest, fileName, .user = TEST_USER_STR, .group = TEST_GROUP_STR, .timeModified = 1), "new write file (defaults)"); TEST_RESULT_VOID(ioWriteOpen(storageWriteIo(file)), "open file"); - TEST_RESULT_INT(ioWriteFd(storageWriteIo(file)), ((StorageWritePosix *)file->driver)->fd, "check write fd"); + TEST_RESULT_INT( + ioWriteFd(storageWriteIo(file)), ((StorageWritePosix *)ioWriteDriver(storageWriteIo(file)))->fd, "check write fd"); TEST_RESULT_VOID(ioWriteClose(storageWriteIo(file)), "close file"); TEST_RESULT_INT(storageInfoP(storageTest, strPath(fileName)).mode, 0750, "check path mode"); TEST_RESULT_INT(storageInfoP(storageTest, fileName).mode, 0640, "check file mode"); @@ -1023,7 +1025,7 @@ testRun(void) "new write file (set mode)"); TEST_RESULT_VOID(ioWriteOpen(storageWriteIo(file)), "open file"); TEST_RESULT_VOID(ioWriteClose(storageWriteIo(file)), "close file"); - TEST_RESULT_VOID(storageWritePosixClose(file->driver), "close file again"); + TEST_RESULT_VOID(storageWritePosixClose(ioWriteDriver(storageWriteIo(file))), "close file again"); TEST_RESULT_INT(storageInfoP(storageTest, strPath(fileName)).mode, 0700, "check path mode"); TEST_RESULT_INT(storageInfoP(storageTest, fileName).mode, 0600, "check file mode"); } @@ -1209,13 +1211,13 @@ testRun(void) TEST_RESULT_BOOL(ioReadOpen(storageReadIo(file)), true, "open file"); // Close the file descriptor so operations will fail - close(((StorageReadPosix *)file->driver)->fd); + close(((StorageReadPosix *)ioReadDriver(storageReadIo(file)))->fd); TEST_ERROR_FMT( ioRead(storageReadIo(file), outBuffer), FileReadError, "unable to read '%s': [9] Bad file descriptor", strZ(fileName)); // Set file descriptor to -1 so the close on free will not fail - ((StorageReadPosix *)file->driver)->fd = -1; + ((StorageReadPosix *)ioReadDriver(storageReadIo(file)))->fd = -1; // ------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("incremental load"); @@ -1258,7 +1260,8 @@ testRun(void) TEST_RESULT_VOID(ioRead(storageReadIo(file), outBuffer), "no data to load"); TEST_RESULT_UINT(bufUsed(outBuffer), 0, "buffer is empty"); - TEST_RESULT_VOID(storageReadPosix(file->driver, outBuffer, true), "no data to load from driver either"); + TEST_RESULT_VOID( + storageReadPosix(ioReadDriver(storageReadIo(file)), outBuffer, true), "no data to load from driver either"); TEST_RESULT_UINT(bufUsed(outBuffer), 0, "buffer is empty"); TEST_RESULT_BOOL(bufEq(buffer, expectedBuffer), true, "check file contents (all loaded)"); @@ -1329,25 +1332,25 @@ testRun(void) TEST_RESULT_VOID(ioWriteOpen(storageWriteIo(file)), "open file"); // Close the file descriptor so operations will fail - close(((StorageWritePosix *)file->driver)->fd); + close(((StorageWritePosix *)ioWriteDriver(storageWriteIo(file)))->fd); storageRemoveP(storageTest, fileTmp, .errorOnMissing = true); TEST_ERROR_FMT( - storageWritePosix(file->driver, buffer), FileWriteError, "unable to write '%s.pgbackrest.tmp': [9] Bad file descriptor", - strZ(fileName)); + storageWritePosix(ioWriteDriver(storageWriteIo(file)), buffer), FileWriteError, + "unable to write '%s.pgbackrest.tmp': [9] Bad file descriptor", strZ(fileName)); TEST_ERROR_FMT( - storageWritePosixClose(file->driver), FileSyncError, STORAGE_ERROR_WRITE_SYNC ": [9] Bad file descriptor", - strZ(fileTmp)); + storageWritePosixClose(ioWriteDriver(storageWriteIo(file))), FileSyncError, + STORAGE_ERROR_WRITE_SYNC ": [9] Bad file descriptor", strZ(fileTmp)); // Disable file sync so close() can be reached - ((StorageWritePosix *)file->driver)->interface.syncFile = false; + ((StorageWritePosix *)ioWriteDriver(storageWriteIo(file)))->interface.syncFile = false; TEST_ERROR_FMT( - storageWritePosixClose(file->driver), FileCloseError, STORAGE_ERROR_WRITE_CLOSE ": [9] Bad file descriptor", - strZ(fileTmp)); + storageWritePosixClose(ioWriteDriver(storageWriteIo(file))), FileCloseError, + STORAGE_ERROR_WRITE_CLOSE ": [9] Bad file descriptor", strZ(fileTmp)); // Set file descriptor to -1 so the close on free with not fail - ((StorageWritePosix *)file->driver)->fd = -1; + ((StorageWritePosix *)ioWriteDriver(storageWriteIo(file)))->fd = -1; // ------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("fail rename in close"); @@ -1364,7 +1367,7 @@ testRun(void) strZ(fileTmp), strZ(fileName)); // Set file descriptor to -1 so the close on free with not fail - ((StorageWritePosix *)file->driver)->fd = -1; + ((StorageWritePosix *)ioWriteDriver(storageWriteIo(file)))->fd = -1; storageRemoveP(storageTest, fileName, .errorOnMissing = true); diff --git a/test/src/module/storage/remoteTest.c b/test/src/module/storage/remoteTest.c index 92a97a1cd2..767286cc07 100644 --- a/test/src/module/storage/remoteTest.c +++ b/test/src/module/storage/remoteTest.c @@ -277,7 +277,9 @@ testRun(void) 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_ASSIGN( + size, storageReadRemote(ioReadDriver(storageReadIo(fileReadRaw)), 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"); @@ -295,8 +297,8 @@ testRun(void) TEST_RESULT_BOOL(bufEq(storageGetP(fileRead), contentBuf), true, "get file"); TEST_RESULT_BOOL(storageReadIgnoreMissing(fileRead), false, "check ignore missing"); TEST_RESULT_STR_Z(storageReadName(fileRead), TEST_PATH "/repo128/test.txt", "check name"); - TEST_RESULT_UINT(storageReadRemote(fileRead->driver, bufNew(32), false), 0, "nothing more to read"); - TEST_RESULT_UINT(((StorageReadRemote *)fileRead->driver)->protocolReadBytes, bufSize(contentBuf), "check read size"); + TEST_RESULT_UINT(storageReadRemote(ioReadDriver(storageReadIo(fileRead)), bufNew(32), false), 0, "nothing more to read"); + TEST_RESULT_UINT(((StorageReadRemote *)ioReadDriver(storageReadIo(fileRead)))->protocolReadBytes, bufSize(contentBuf), "check read size"); // Enable protocol compression in the storage object ((StorageRemote *)storageDriver(storageRepo))->compressLevel = 3; @@ -306,7 +308,7 @@ testRun(void) TEST_ASSIGN(fileRead, storageNewReadP(storageRepo, STRDEF("test.txt"), .limit = VARUINT64(11)), "get file"); TEST_RESULT_STR_Z(strNewBuf(storageGetP(fileRead)), "BABABABABAB", "check contents"); - TEST_RESULT_UINT(((StorageReadRemote *)fileRead->driver)->protocolReadBytes, 11, "check read size"); + TEST_RESULT_UINT(((StorageReadRemote *)ioReadDriver(storageReadIo(fileRead)))->protocolReadBytes, 11, "check read size"); // ------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("read partial file then close"); @@ -358,7 +360,8 @@ testRun(void) TEST_RESULT_BOOL(bufEq(storageGetP(fileRead), contentBuf), true, "check contents"); // We don't know how much protocol compression there will be exactly, but make sure this is some TEST_RESULT_BOOL( - ((StorageReadRemote *)fileRead->driver)->protocolReadBytes < bufSize(contentBuf), true, "check compressed read size"); + ((StorageReadRemote *)ioReadDriver(storageReadIo(fileRead)))->protocolReadBytes < bufSize(contentBuf), true, + "check compressed read size"); // ------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("file missing"); @@ -446,8 +449,10 @@ testRun(void) TEST_RESULT_BOOL(storageWriteTruncate(write), true, "file will be truncated"); TEST_RESULT_VOID(storagePutP(write, contentBuf), "write file"); - TEST_RESULT_UINT(((StorageWriteRemote *)write->driver)->protocolWriteBytes, bufSize(contentBuf), "check write size"); - TEST_RESULT_VOID(storageWriteRemoteClose(write->driver), "close file again"); + TEST_RESULT_UINT( + ((StorageWriteRemote *)ioWriteDriver(storageWriteIo(write)))->protocolWriteBytes, bufSize(contentBuf), + "check write size"); + TEST_RESULT_VOID(storageWriteRemoteClose(ioWriteDriver(storageWriteIo(write))), "close file again"); TEST_RESULT_VOID(storageWriteFree(write), "free file"); // Make sure the file was written correctly @@ -503,7 +508,8 @@ testRun(void) write, storageNewWriteP(storageRepoWrite, STRDEF("test2.txt"), .compressible = true), "new write file (compress)"); TEST_RESULT_VOID(storagePutP(write, contentBuf), "write file"); TEST_RESULT_BOOL( - ((StorageWriteRemote *)write->driver)->protocolWriteBytes < bufSize(contentBuf), true, "check compressed write size"); + ((StorageWriteRemote *)ioWriteDriver(storageWriteIo(write)))->protocolWriteBytes < bufSize(contentBuf), true, + "check compressed write size"); } // ***************************************************************************************************************************** diff --git a/test/src/module/storage/s3Test.c b/test/src/module/storage/s3Test.c index aecd6674fc..5c3f466610 100644 --- a/test/src/module/storage/s3Test.c +++ b/test/src/module/storage/s3Test.c @@ -747,7 +747,7 @@ testRun(void) TEST_RESULT_BOOL(storageWriteSyncPath(write), true, "path is synced"); TEST_RESULT_BOOL(storageWriteTruncate(write), true, "file will be truncated"); - TEST_RESULT_VOID(storageWriteS3Close(write->driver), "close file again"); + TEST_RESULT_VOID(storageWriteS3Close(ioWriteDriver(storageWriteIo(write))), "close file again"); // Check that temp credentials were changed TEST_RESULT_STR_Z(driver->accessKey, "xx", "check access key"); diff --git a/test/src/module/storage/sftpTest.c b/test/src/module/storage/sftpTest.c index 5c3e451f22..3243b6f72a 100644 --- a/test/src/module/storage/sftpTest.c +++ b/test/src/module/storage/sftpTest.c @@ -4686,7 +4686,7 @@ testRun(void) TEST_ASSIGN(file, storageNewReadP(storageTest, fileName), "new read file (defaults)"); TEST_RESULT_BOOL(ioReadOpen(storageReadIo(file)), true, "open file"); - TEST_RESULT_VOID(storageReadSftpClose((StorageReadSftp *)file->driver), "close file"); + TEST_RESULT_VOID(storageReadSftpClose((StorageReadSftp *)ioReadDriver(storageReadIo(file))), "close file"); memContextFree(objMemContext((StorageSftp *)storageDriver(storageTest))); @@ -4714,7 +4714,7 @@ testRun(void) TEST_ASSIGN(file, storageNewReadP(storageTest, fileName), "new read file (defaults)"); TEST_RESULT_BOOL(ioReadOpen(storageReadIo(file)), true, "open file"); - close(ioSessionFd(((StorageReadSftp *)file->driver)->storage->ioSession)); + close(ioSessionFd(((StorageReadSftp *)ioReadDriver(storageReadIo(file)))->storage->ioSession)); memContextFree(objMemContext((StorageSftp *)storageDriver(storageTest))); @@ -4742,8 +4742,8 @@ testRun(void) TEST_ASSIGN(file, storageNewReadP(storageTest, fileName), "new read file (defaults)"); TEST_RESULT_BOOL(ioReadOpen(storageReadIo(file)), true, "open file"); - ((StorageReadSftp *)file->driver)->sftpHandle = NULL; - TEST_RESULT_VOID(storageReadSftpClose((StorageReadSftp *)file->driver), "close file null sftpHandle"); + ((StorageReadSftp *)ioReadDriver(storageReadIo(file)))->sftpHandle = NULL; + TEST_RESULT_VOID(storageReadSftpClose(ioReadDriver(storageReadIo(file))), "close file null sftpHandle"); memContextFree(objMemContext((StorageSftp *)storageDriver(storageTest))); @@ -4776,7 +4776,7 @@ testRun(void) TEST_ASSIGN(file, storageNewReadP(storageTest, fileName), "new read file (defaults)"); TEST_RESULT_BOOL(ioReadOpen(storageReadIo(file)), true, "open file"); TEST_ERROR( - storageReadSftpClose((StorageReadSftp *)file->driver), FileCloseError, + storageReadSftpClose(ioReadDriver(storageReadIo(file))), FileCloseError, "timeout closing file '" TEST_PATH "/readtest.txt': libssh2 error [-37]"); memContextFree(objMemContext((StorageSftp *)storageDriver(storageTest))); @@ -4810,7 +4810,7 @@ testRun(void) TEST_ASSIGN(file, storageNewReadP(storageTest, fileName), "new read file (defaults)"); TEST_RESULT_BOOL(ioReadOpen(storageReadIo(file)), true, "open file"); TEST_ERROR( - storageReadSftpClose((StorageReadSftp *)file->driver), FileCloseError, + storageReadSftpClose(ioReadDriver(storageReadIo(file))), FileCloseError, "unable to close file '" TEST_PATH "/readtest.txt' after read: libssh2 errno [-31]: sftp errno [4]"); memContextFree(objMemContext((StorageSftp *)storageDriver(storageTest))); @@ -4843,7 +4843,7 @@ testRun(void) TEST_ASSIGN(file, storageNewReadP(storageTest, fileName), "new read file (defaults)"); TEST_RESULT_BOOL(ioReadOpen(storageReadIo(file)), true, "open file"); TEST_ERROR( - storageReadSftpClose((StorageReadSftp *)file->driver), FileCloseError, + storageReadSftpClose(ioReadDriver(storageReadIo(file))), FileCloseError, "unable to close file '" TEST_PATH "/readtest.txt' after read: libssh2 errno [-29]"); memContextFree(objMemContext((StorageSftp *)storageDriver(storageTest))); @@ -4875,7 +4875,7 @@ testRun(void) TEST_ASSIGN(file, storageNewReadP(storageTest, fileName), "new read file (defaults)"); TEST_RESULT_BOOL(ioReadOpen(storageReadIo(file)), true, "open file"); TEST_ERROR( - storageReadSftp(((StorageReadSftp *)file->driver), outBuffer, false), FileReadError, + storageReadSftp(ioReadDriver(storageReadIo(file)), outBuffer, false), FileReadError, "unable to read '" TEST_PATH "/readtest.txt': sftp errno [4]"); memContextFree(objMemContext((StorageSftp *)storageDriver(storageTest))); @@ -4907,7 +4907,7 @@ testRun(void) TEST_ASSIGN(file, storageNewReadP(storageTest, fileName), "new read file (defaults)"); TEST_RESULT_BOOL(ioReadOpen(storageReadIo(file)), true, "open file"); TEST_ERROR( - storageReadSftp(((StorageReadSftp *)file->driver), outBuffer, false), FileReadError, + storageReadSftp(ioReadDriver(storageReadIo(file)), outBuffer, false), FileReadError, "unable to read '" TEST_PATH "/readtest.txt': libssh2 error [-29]"); memContextFree(objMemContext((StorageSftp *)storageDriver(storageTest))); @@ -5546,7 +5546,7 @@ testRun(void) ((StorageSftp *)storageDriver(storageTest))->interface.pathSync = malloc(1); TEST_ASSIGN(file, storageNewWriteP(storageTest, fileName, .noAtomic = true, .noSyncPath = false), "new write file"); - ((StorageWriteSftp *)file->driver)->interface.syncFile = false; + ((StorageWriteSftp *)ioWriteDriver(storageWriteIo(file)))->interface.syncFile = false; TEST_RESULT_VOID(ioWriteOpen(storageWriteIo(file)), "open file"); TEST_RESULT_INT(ioWriteFd(storageWriteIo(file)), -1, "check write fd"); TEST_RESULT_VOID(ioWriteClose(storageWriteIo(file)), "close file"); @@ -5586,7 +5586,7 @@ testRun(void) TEST_RESULT_INT(ioWriteFd(storageWriteIo(file)), -1, "check write fd"); // Make sftpHandle NULL - ((StorageWriteSftp *)file->driver)->sftpHandle = NULL; + ((StorageWriteSftp *)ioWriteDriver(storageWriteIo(file)))->sftpHandle = NULL; TEST_RESULT_VOID(ioWriteClose(storageWriteIo(file)), "close file"); @@ -6761,14 +6761,14 @@ testRun(void) TEST_RESULT_VOID(ioRead(storageReadIo(file), outBuffer), "no data to load"); TEST_RESULT_UINT(bufUsed(outBuffer), 0, "buffer is empty"); - TEST_RESULT_VOID(storageReadSftp(file->driver, outBuffer, true), "no data to load from driver either"); + TEST_RESULT_VOID(storageReadSftp(ioReadDriver(storageReadIo(file)), outBuffer, true), "no data to load from driver either"); TEST_RESULT_UINT(bufUsed(outBuffer), 0, "buffer is empty"); TEST_RESULT_BOOL(bufEq(buffer, expectedBuffer), true, "check file contents (all loaded)"); TEST_RESULT_BOOL(ioReadEof(storageReadIo(file)), true, "eof"); TEST_RESULT_BOOL(ioReadEof(storageReadIo(file)), true, "still eof"); - TEST_RESULT_BOOL(storageReadSftpEof((StorageReadSftp *)file->driver), true, "storageReadSftpEof eof true"); + TEST_RESULT_BOOL(storageReadSftpEof(ioReadDriver(storageReadIo(file))), true, "storageReadSftpEof eof true"); TEST_RESULT_VOID(ioReadClose(storageReadIo(file)), "close file");