1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-15 01:04:37 +02:00

Allow end anchor to be excluded in backupRegExp().

This is useful for matching files in the backup history directory which have characters after the backup label.
This commit is contained in:
David Steele
2019-12-12 18:52:16 -05:00
parent 8acfb6adf4
commit e206093beb
3 changed files with 6 additions and 6 deletions

View File

@ -26,6 +26,7 @@ backupRegExp(BackupRegExpParam param)
FUNCTION_LOG_PARAM(BOOL, param.full); FUNCTION_LOG_PARAM(BOOL, param.full);
FUNCTION_LOG_PARAM(BOOL, param.differential); FUNCTION_LOG_PARAM(BOOL, param.differential);
FUNCTION_LOG_PARAM(BOOL, param.incremental); FUNCTION_LOG_PARAM(BOOL, param.incremental);
FUNCTION_LOG_PARAM(BOOL, param.noAnchorEnd);
FUNCTION_LOG_END(); FUNCTION_LOG_END();
ASSERT(param.full || param.differential || param.incremental); ASSERT(param.full || param.differential || param.incremental);
@ -76,6 +77,7 @@ backupRegExp(BackupRegExpParam param)
} }
// Append the end anchor // Append the end anchor
if (!param.noAnchorEnd)
strCat(result, "$"); strCat(result, "$");
FUNCTION_LOG_RETURN(STRING, result); FUNCTION_LOG_RETURN(STRING, result);

View File

@ -33,6 +33,7 @@ typedef struct BackupRegExpParam
bool full; bool full;
bool differential; bool differential;
bool incremental; bool incremental;
bool noAnchorEnd;
} BackupRegExpParam; } BackupRegExpParam;
#define backupRegExpP(...) \ #define backupRegExpP(...) \

View File

@ -90,17 +90,14 @@ testRun(void)
TEST_RESULT_BOOL(regExpMatchOne(filter, full), true, " match full"); TEST_RESULT_BOOL(regExpMatchOne(filter, full), true, " match full");
// ------------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------------
filter = backupRegExpP(.incremental = true, .differential = true); filter = backupRegExpP(.incremental = true, .differential = true, .noAnchorEnd = true);
TEST_RESULT_STR( TEST_RESULT_STR(
strPtr(filter), strPtr(filter),
"^[0-9]{8}\\-[0-9]{6}F\\_[0-9]{8}\\-[0-9]{6}(D|I)$", "diff and incr backup regex with anchors"); "^[0-9]{8}\\-[0-9]{6}F\\_[0-9]{8}\\-[0-9]{6}(D|I)", "diff and incr backup regex with anchors");
TEST_RESULT_BOOL(regExpMatchOne(filter, incr), true, " match incr"); TEST_RESULT_BOOL(regExpMatchOne(filter, incr), true, " match incr");
TEST_RESULT_BOOL(regExpMatchOne(filter, diff), true, " match diff"); TEST_RESULT_BOOL(regExpMatchOne(filter, diff), true, " match diff");
TEST_RESULT_BOOL(regExpMatchOne(filter, full), false, " does not match full"); TEST_RESULT_BOOL(regExpMatchOne(filter, full), false, " does not match full");
TEST_RESULT_BOOL(
regExpMatchOne(
filter, strNew("12341234-123123F_12341234-123123DG")), false, " does not match with trailing character");
TEST_RESULT_BOOL( TEST_RESULT_BOOL(
regExpMatchOne( regExpMatchOne(
filter, strNew("A12341234-123123F_12341234-123123I")), false, " does not match with leading character"); filter, strNew("A12341234-123123F_12341234-123123I")), false, " does not match with leading character");