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

Convert storagePosixNew() to storagePosixNewP().

An upcoming feature requires new parameters for storagePosixNew() and this causes a lot of churn because almost every test creates a Posix storage object. Some refactoring in the tests might reduce this duplication but storagePosixNew() is collecting a lot of parameters so converting to storagePosixNewP() makes sense in any case.

There are relatively few call sites in the core code but they still benefit from better readability after this change.
This commit is contained in:
David Steele 2020-04-30 11:01:38 -04:00
parent baf8cb9068
commit 22ba1f02ce
26 changed files with 67 additions and 87 deletions

View File

@ -132,8 +132,7 @@ storageLocal(void)
MEM_CONTEXT_BEGIN(storageHelper.memContext)
{
storageHelper.storageLocal = storagePosixNew(
FSLASH_STR, STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, false, NULL);
storageHelper.storageLocal = storagePosixNewP(FSLASH_STR);
}
MEM_CONTEXT_END();
}
@ -152,8 +151,7 @@ storageLocalWrite(void)
MEM_CONTEXT_BEGIN(storageHelper.memContext)
{
storageHelper.storageLocalWrite = storagePosixNew(
FSLASH_STR, STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, true, NULL);
storageHelper.storageLocalWrite = storagePosixNewP(FSLASH_STR, .write = true);
}
MEM_CONTEXT_END();
}
@ -184,8 +182,7 @@ storagePgGet(unsigned int hostId, bool write)
// Use Posix storage
else
{
result = storagePosixNew(
cfgOptionStr(cfgOptPgPath + hostId - 1), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, write, NULL);
result = storagePosixNewP(cfgOptionStr(cfgOptPgPath + hostId - 1), .write = write);
}
FUNCTION_TEST_RETURN(result);
@ -362,8 +359,8 @@ storageRepoGet(const String *type, bool write)
// Use Posix storage
else if (strEqZ(type, STORAGE_TYPE_POSIX))
{
result = storagePosixNew(
cfgOptionStr(cfgOptRepoPath), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, write, storageRepoPathExpression);
result = storagePosixNewP(
cfgOptionStr(cfgOptRepoPath), .write = write, .pathExpressionFunction = storageRepoPathExpression);
}
// Use S3 storage
else if (strEqZ(type, STORAGE_TYPE_S3))
@ -488,9 +485,8 @@ storageSpool(void)
MEM_CONTEXT_BEGIN(storageHelper.memContext)
{
storageHelper.storageSpool = storagePosixNew(
cfgOptionStr(cfgOptSpoolPath), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, false,
storageSpoolPathExpression);
storageHelper.storageSpool = storagePosixNewP(
cfgOptionStr(cfgOptSpoolPath), .pathExpressionFunction = storageSpoolPathExpression);
}
MEM_CONTEXT_END();
}
@ -514,9 +510,8 @@ storageSpoolWrite(void)
MEM_CONTEXT_BEGIN(storageHelper.memContext)
{
storageHelper.storageSpoolWrite = storagePosixNew(
cfgOptionStr(cfgOptSpoolPath), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, true,
storageSpoolPathExpression);
storageHelper.storageSpoolWrite = storagePosixNewP(
cfgOptionStr(cfgOptSpoolPath), .write = true, .pathExpressionFunction = storageSpoolPathExpression);
}
MEM_CONTEXT_END();
}

View File

@ -614,17 +614,19 @@ storagePosixNewInternal(
}
Storage *
storagePosixNew(
const String *path, mode_t modeFile, mode_t modePath, bool write, StoragePathExpressionCallback pathExpressionFunction)
storagePosixNew(const String *path, StoragePosixNewParam param)
{
FUNCTION_LOG_BEGIN(logLevelDebug);
FUNCTION_LOG_PARAM(STRING, path);
FUNCTION_LOG_PARAM(MODE, modeFile);
FUNCTION_LOG_PARAM(MODE, modePath);
FUNCTION_LOG_PARAM(BOOL, write);
FUNCTION_LOG_PARAM(FUNCTIONP, pathExpressionFunction);
FUNCTION_LOG_PARAM(MODE, param.modeFile);
FUNCTION_LOG_PARAM(MODE, param.modePath);
FUNCTION_LOG_PARAM(BOOL, param.write);
FUNCTION_LOG_PARAM(FUNCTIONP, param.pathExpressionFunction);
FUNCTION_LOG_END();
FUNCTION_LOG_RETURN(
STORAGE, storagePosixNewInternal(STORAGE_POSIX_TYPE_STR, path, modeFile, modePath, write, pathExpressionFunction, true));
STORAGE,
storagePosixNewInternal(
STORAGE_POSIX_TYPE_STR, path, param.modeFile == 0 ? STORAGE_MODE_FILE_DEFAULT : param.modeFile,
param.modePath == 0 ? STORAGE_MODE_PATH_DEFAULT : param.modePath, param.write, param.pathExpressionFunction, true));
}

View File

@ -20,7 +20,18 @@ Storage type
/***********************************************************************************************************************************
Constructors
***********************************************************************************************************************************/
Storage *storagePosixNew(
const String *path, mode_t modeFile, mode_t modePath, bool write, StoragePathExpressionCallback pathExpressionFunction);
typedef struct StoragePosixNewParam
{
VAR_PARAM_HEADER;
bool write;
mode_t modeFile;
mode_t modePath;
StoragePathExpressionCallback *pathExpressionFunction;
} StoragePosixNewParam;
#define storagePosixNewP(path, ...) \
storagePosixNew(path, (StoragePosixNewParam){VAR_PARAM_INIT, __VA_ARGS__})
Storage *storagePosixNew(const String *path, StoragePosixNewParam param);
#endif

View File

@ -18,8 +18,7 @@ testRun(void)
FUNCTION_HARNESS_VOID();
// Create default storage object for testing
Storage *storageTest = storagePosixNew(
strNew(testPath()), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, true, NULL);
Storage *storageTest = storagePosixNewP(strNew(testPath()), .write = true);
// *****************************************************************************************************************************
if (testBegin("archiveAsyncErrorClear() and archiveAsyncStatus()"))

View File

@ -20,8 +20,7 @@ testRun(void)
{
FUNCTION_HARNESS_VOID();
Storage *storageTest = storagePosixNew(
strNew(testPath()), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, true, NULL);
Storage *storageTest = storagePosixNewP(strNew(testPath()), .write = true);
// Start a protocol server to test the protocol directly
Buffer *serverWrite = bufNew(8192);

View File

@ -22,8 +22,7 @@ testRun(void)
FUNCTION_HARNESS_VOID();
// Create default storage object for testing
Storage *storageTest = storagePosixNew(
strNew(testPath()), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, true, NULL);
Storage *storageTest = storagePosixNewP(strNew(testPath()), .write = true);
// Start a protocol server to test the protocol directly
Buffer *serverWrite = bufNew(8192);

View File

@ -456,8 +456,7 @@ testRun(void)
// The tests expect the timezone to be UTC
setenv("TZ", "UTC", true);
Storage *storageTest = storagePosixNew(
strNew(testPath()), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, true, NULL);
Storage *storageTest = storagePosixNewP(strNew(testPath()), .write = true);
// Start a protocol server to test the protocol directly
Buffer *serverWrite = bufNew(8192);

View File

@ -24,8 +24,7 @@ testRun(void)
// PQfinish() is strictly checked
harnessPqScriptStrictSet(true);
Storage *storageTest = storagePosixNew(
strNew(testPath()), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, true, NULL);
Storage *storageTest = storagePosixNewP(strNew(testPath()), .write = true);
String *pg1 = strNew("pg1");
String *pg1Path = strNewFmt("%s/%s", testPath(), strPtr(pg1));

View File

@ -16,8 +16,7 @@ testRun(void)
FUNCTION_HARNESS_VOID();
// Create default storage object for testing
Storage *storageData = storagePosixNew(
strNew(testDataPath()), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, true, NULL);
Storage *storageData = storagePosixNewP(strNew(testDataPath()), .write = true);
// *****************************************************************************************************************************
if (testBegin("lockStopFileName()"))

View File

@ -71,8 +71,7 @@ testRun(void)
{
FUNCTION_HARNESS_VOID();
Storage *storageTest = storagePosixNew(
strNew(testPath()), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, true, NULL);
Storage *storageTest = storagePosixNewP(strNew(testPath()), .write = true);
String *backupStanzaPath = strNew("repo/backup/db");
String *backupInfoFileName = strNewFmt("%s/backup.info", strPtr(backupStanzaPath));

View File

@ -413,8 +413,7 @@ testRun(void)
// Restore normal stdout
dup2(stdoutSave, STDOUT_FILENO);
Storage *storage = storagePosixNew(
strNew(testPath()), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, false, NULL);
Storage *storage = storagePosixNewP(strNew(testPath()));
TEST_RESULT_STR_Z(strNewBuf(storageGetP(storageNewReadP(storage, stdoutFile))), generalHelp, " check text");
}

View File

@ -1312,8 +1312,7 @@ testRun(void)
// Restore normal stdout
dup2(stdoutSave, STDOUT_FILENO);
Storage *storage = storagePosixNew(
strNew(testPath()), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, false, NULL);
Storage *storage = storagePosixNewP(strNew(testPath()));
TEST_RESULT_STR_Z(
strNewBuf(storageGetP(storageNewReadP(storage, stdoutFile))), "No stanzas exist in the repository.\n",
" check text");

View File

@ -19,8 +19,7 @@ testRun(void)
FUNCTION_HARNESS_VOID();
// Create default storage object for testing
Storage *storageData = storagePosixNew(
strNew(testDataPath()), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, true, NULL);
Storage *storageData = storagePosixNewP(strNew(testDataPath()), .write = true);
// *****************************************************************************************************************************
if (testBegin("cmdRemote()"))
@ -157,9 +156,7 @@ testRun(void)
protocolClientNoOp(client);
TEST_RESULT_BOOL(
storageExistsP(
storagePosixNew(strNew(testDataPath()), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, false, NULL),
STRDEF("lock/test-archive" LOCK_FILE_EXT)),
storageExistsP(storagePosixNewP(strNew(testDataPath())), STRDEF("lock/test-archive" LOCK_FILE_EXT)),
true, "lock exists");
protocolClientFree(client);

View File

@ -16,8 +16,7 @@ testRun(void)
FUNCTION_HARNESS_VOID();
// Create default storage object for testing
Storage *storageTest = storagePosixNew(
strNew(testPath()), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, true, NULL);
Storage *storageTest = storagePosixNewP(strNew(testPath()), .write = true);
// *****************************************************************************************************************************
if (testBegin("cmdRepoCreate()"))

View File

@ -148,8 +148,7 @@ testRun(void)
FUNCTION_HARNESS_VOID();
// Create default storage object for testing
Storage *storageTest = storagePosixNew(
strNew(testPath()), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, true, NULL);
Storage *storageTest = storagePosixNewP(strNew(testPath()), .write = true);
// *****************************************************************************************************************************
if (testBegin("restoreFile()"))

View File

@ -17,8 +17,7 @@ testRun(void)
{
FUNCTION_HARNESS_VOID();
Storage *storageTest = storagePosixNew(
strNew(testPath()), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, true, NULL);
Storage *storageTest = storagePosixNewP(strNew(testPath()), .write = true);
String *stanza = strNew("db");
String *fileName = strNew("test.info");

View File

@ -83,7 +83,7 @@ testSuite(CompressType type, const char *decompressCmd)
varLstAdd(compressParamList, varNewUInt(1));
// Create default storage object for testing
Storage *storageTest = storagePosixNew(strNew(testPath()), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, true, NULL);
Storage *storageTest = storagePosixNewP(strNew(testPath()), .write = true);
TEST_TITLE("simple data");

View File

@ -15,8 +15,7 @@ testRun(void)
FUNCTION_HARNESS_VOID();
// Create default storage object for testing
Storage *storageTest = storagePosixNew(
strNew(testPath()), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, true, NULL);
Storage *storageTest = storagePosixNewP(strNew(testPath()), .write = true);
// *****************************************************************************************************************************
if (testBegin("lockAcquireFile() and lockReleaseFile()"))

View File

@ -16,8 +16,7 @@ void
testRun(void)
{
// Create default storage object for testing
Storage *storageTest = storagePosixNew(
strNew(testPath()), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, true, NULL);
Storage *storageTest = storagePosixNewP(strNew(testPath()), .write = true);
// *****************************************************************************************************************************
if (testBegin("InfoArchive"))

View File

@ -16,8 +16,7 @@ void
testRun(void)
{
// Create default storage object for testing
Storage *storageTest = storagePosixNew(
strNew(testPath()), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, true, NULL);
Storage *storageTest = storagePosixNewP(strNew(testPath()), .write = true);
// *****************************************************************************************************************************
if (testBegin("InfoBackup"))

View File

@ -21,8 +21,7 @@ Test Run
void
testRun(void)
{
Storage *storageTest = storagePosixNew(
strNew(testPath()), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, true, NULL);
Storage *storageTest = storagePosixNewP(strNew(testPath()), .write = true);
// *****************************************************************************************************************************
if (testBegin("struct sizes"))
@ -174,10 +173,8 @@ testRun(void)
storagePathCreateP(storageTest, strNew("pg"), .mode = 0700, .noParentCreate = true);
Storage *storagePg = storagePosixNew(
strNewFmt("%s/pg", testPath()), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, false, NULL);
Storage *storagePgWrite = storagePosixNew(
strNewFmt("%s/pg", testPath()), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, true, NULL);
Storage *storagePg = storagePosixNewP(strNewFmt("%s/pg", testPath()));
Storage *storagePgWrite = storagePosixNewP(strNewFmt("%s/pg", testPath()), .write = true);
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("8.3 with custom exclusions and special file");

View File

@ -277,11 +277,7 @@ testRun(void)
uint64_t rateOut = 100000;
// Get the sample pages from disk
Buffer *block = storageGetP(
storageNewReadP(
storagePosixNew(STR(testRepoPath()), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, false, NULL),
STRDEF("test/data/filecopy.table.bin")));
Buffer *block = storageGetP(storageNewReadP(storagePosixNewP(STR(testRepoPath())), STRDEF("test/data/filecopy.table.bin")));
ASSERT(bufUsed(block) == 1024 * 1024);
// -------------------------------------------------------------------------------------------------------------------------

View File

@ -11,8 +11,7 @@ testRun(void)
{
FUNCTION_HARNESS_VOID();
Storage *storageTest = storagePosixNew(
strNew(testPath()), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, true, NULL);
Storage *storageTest = storagePosixNewP(strNew(testPath()), .write = true);
// *****************************************************************************************************************************
if (testBegin("pgVersionFromStr() and pgVersionToStr()"))

View File

@ -97,8 +97,7 @@ testRun(void)
{
FUNCTION_HARNESS_VOID();
Storage *storageTest = storagePosixNew(
strNew(testPath()), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, true, NULL);
Storage *storageTest = storagePosixNewP(strNew(testPath()), .write = true);
// *****************************************************************************************************************************
if (testBegin("protocolStorageTypeEnum() and protocolStorageTypeEnum()"))

View File

@ -48,10 +48,8 @@ testRun(void)
FUNCTION_HARNESS_VOID();
// Create default storage object for testing
Storage *storageTest = storagePosixNew(
strNew(testPath()), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, true, NULL);
Storage *storageTmp = storagePosixNew(
strNew("/tmp"), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, true, NULL);
Storage *storageTest = storagePosixNewP(strNew(testPath()), .write = true);
Storage *storageTmp = storagePosixNewP(strNew("/tmp"), .write = true);
ioBufferSizeSet(2);
// Directory and file that cannot be accessed to test permissions errors
@ -86,7 +84,7 @@ testRun(void)
if (testBegin("storageNew() and storageFree()"))
{
Storage *storageTest = NULL;
TEST_ASSIGN(storageTest, storagePosixNew(strNew("/"), 0640, 0750, false, NULL), "new storage (defaults)");
TEST_ASSIGN(storageTest, storagePosixNewP(strNew("/")), "new storage (defaults)");
TEST_RESULT_STR_Z(storageTest->path, "/", " check path");
TEST_RESULT_INT(storageTest->modeFile, 0640, " check file mode");
TEST_RESULT_INT(storageTest->modePath, 0750, " check path mode");
@ -94,7 +92,10 @@ testRun(void)
TEST_RESULT_BOOL(storageTest->pathExpressionFunction == NULL, true, " check expression function is not set");
TEST_ASSIGN(
storageTest, storagePosixNew(strNew("/path/to"), 0600, 0700, true, storageTestPathExpression),
storageTest,
storagePosixNewP(
strNew("/path/to"), .modeFile = 0600, .modePath = 0700, .write = true,
.pathExpressionFunction = storageTestPathExpression),
"new storage (non-default)");
TEST_RESULT_STR_Z(storageTest->path, "/path/to", " check path");
TEST_RESULT_INT(storageTest->modeFile, 0600, " check file mode");
@ -543,7 +544,7 @@ testRun(void)
{
Storage *storageTest = NULL;
TEST_ASSIGN(storageTest, storagePosixNew(strNew("/"), 0640, 0750, false, NULL), "new storage /");
TEST_ASSIGN(storageTest, storagePosixNewP(strNew("/")), "new storage /");
TEST_RESULT_STR_Z(storagePathP(storageTest, NULL), "/", " root dir");
TEST_RESULT_STR_Z(storagePathP(storageTest, strNew("/")), "/", " same as root dir");
TEST_RESULT_STR_Z(storagePathP(storageTest, strNew("subdir")), "/subdir", " simple subdir");
@ -553,7 +554,7 @@ testRun(void)
// -------------------------------------------------------------------------------------------------------------------------
TEST_ASSIGN(
storageTest, storagePosixNew(strNew("/path/to"), 0640, 0750, false, storageTestPathExpression),
storageTest, storagePosixNewP(strNew("/path/to"), .pathExpressionFunction = storageTestPathExpression),
"new storage /path/to with expression");
TEST_RESULT_STR_Z(storagePathP(storageTest, NULL), "/path/to", " root dir");
TEST_RESULT_STR_Z(storagePathP(storageTest, strNew("/path/to")), "/path/to", " absolute root dir");
@ -682,8 +683,7 @@ testRun(void)
// -------------------------------------------------------------------------------------------------------------------------
TEST_ERROR_FMT(
storagePathSyncP(
storagePosixNew(strNew("/"), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, true, NULL), strNew("/proc")),
storagePathSyncP(storagePosixNewP(strNew("/"), .write = true), strNew("/proc")),
PathSyncError, STORAGE_ERROR_PATH_SYNC ": [22] Invalid argument", "/proc");
// -------------------------------------------------------------------------------------------------------------------------
@ -767,7 +767,7 @@ testRun(void)
// *****************************************************************************************************************************
if (testBegin("storagePut() and storageGet()"))
{
Storage *storageTest = storagePosixNew(strNew("/"), 0640, 0750, true, NULL);
Storage *storageTest = storagePosixNewP(strNew("/"), .write = true);
TEST_ERROR_FMT(
storageGetP(storageNewReadP(storageTest, strNew(testPath()))), FileReadError,

View File

@ -22,8 +22,7 @@ testRun(void)
FUNCTION_HARNESS_VOID();
// Test storage
Storage *storageTest = storagePosixNew(
strNew(testPath()), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, true, NULL);
Storage *storageTest = storagePosixNewP(strNew(testPath()), .write = true);
// Load configuration to set repo-path and stanza
StringList *argList = strLstNew();