You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-07-17 01:12:23 +02:00
Migrate backupRegExp() to C.
Removed the "anchor" parameter because it was never used in any calls in the Perl code so it was just a dead parameter that always defaulted to true. Contributed by Cynthia Shang.
This commit is contained in:
committed by
David Steele
parent
39ed4f763b
commit
a7281878ac
@ -18,6 +18,14 @@
|
|||||||
<release-item>
|
<release-item>
|
||||||
<p>Automatically generate constants for command and option names.</p>
|
<p>Automatically generate constants for command and option names.</p>
|
||||||
</release-item>
|
</release-item>
|
||||||
|
|
||||||
|
<release-item>
|
||||||
|
<release-item-contributor-list>
|
||||||
|
<release-item-contributor id="cynthia.shang"/>
|
||||||
|
</release-item-contributor-list>
|
||||||
|
|
||||||
|
<p>Migrate <code>backupRegExp()</code> to C.</p>
|
||||||
|
</release-item>
|
||||||
</release-development-list>
|
</release-development-list>
|
||||||
</release-core-list>
|
</release-core-list>
|
||||||
</release>
|
</release>
|
||||||
|
@ -224,6 +224,9 @@ command/archive/push/protocol.o: command/archive/push/protocol.c command/archive
|
|||||||
command/archive/push/push.o: command/archive/push/push.c command/archive/common.h command/archive/push/file.h command/archive/push/protocol.h command/command.h command/control/control.h common/assert.h common/crypto/common.h common/debug.h common/error.auto.h common/error.h common/fork.h common/ini.h common/io/filter/filter.h common/io/filter/group.h common/io/read.h common/io/write.h common/lock.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/time.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/stringList.h common/type/variant.h common/type/variantList.h common/wait.h config/config.auto.h config/config.h config/define.auto.h config/define.h config/exec.h info/infoArchive.h info/infoPg.h postgres/interface.h protocol/client.h protocol/command.h protocol/helper.h protocol/parallel.h protocol/parallelJob.h protocol/server.h storage/fileRead.h storage/fileWrite.h storage/helper.h storage/info.h storage/storage.h
|
command/archive/push/push.o: command/archive/push/push.c command/archive/common.h command/archive/push/file.h command/archive/push/protocol.h command/command.h command/control/control.h common/assert.h common/crypto/common.h common/debug.h common/error.auto.h common/error.h common/fork.h common/ini.h common/io/filter/filter.h common/io/filter/group.h common/io/read.h common/io/write.h common/lock.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/time.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/stringList.h common/type/variant.h common/type/variantList.h common/wait.h config/config.auto.h config/config.h config/define.auto.h config/define.h config/exec.h info/infoArchive.h info/infoPg.h postgres/interface.h protocol/client.h protocol/command.h protocol/helper.h protocol/parallel.h protocol/parallelJob.h protocol/server.h storage/fileRead.h storage/fileWrite.h storage/helper.h storage/info.h storage/storage.h
|
||||||
$(CC) $(CFLAGS) -c command/archive/push/push.c -o command/archive/push/push.o
|
$(CC) $(CFLAGS) -c command/archive/push/push.c -o command/archive/push/push.o
|
||||||
|
|
||||||
|
command/backup/common.o: command/backup/common.c command/backup/common.h common/assert.h common/debug.h common/error.auto.h common/error.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/string.h
|
||||||
|
$(CC) $(CFLAGS) -c command/backup/common.c -o command/backup/common.o
|
||||||
|
|
||||||
command/command.o: command/command.c common/assert.h common/debug.h common/error.auto.h common/error.h common/lock.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/time.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/stringList.h common/type/variant.h common/type/variantList.h config/config.auto.h config/config.h config/define.auto.h config/define.h version.h
|
command/command.o: command/command.c common/assert.h common/debug.h common/error.auto.h common/error.h common/lock.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/time.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/stringList.h common/type/variant.h common/type/variantList.h config/config.auto.h config/config.h config/define.auto.h config/define.h version.h
|
||||||
$(CC) $(CFLAGS) -c command/command.c -o command/command.o
|
$(CC) $(CFLAGS) -c command/command.c -o command/command.o
|
||||||
|
|
||||||
|
76
src/command/backup/common.c
Normal file
76
src/command/backup/common.c
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
/***********************************************************************************************************************************
|
||||||
|
Common Functions and Definitions for Backup and Expire Commands
|
||||||
|
***********************************************************************************************************************************/
|
||||||
|
#include "command/backup/common.h"
|
||||||
|
#include "common/debug.h"
|
||||||
|
#include "common/log.h"
|
||||||
|
|
||||||
|
/***********************************************************************************************************************************
|
||||||
|
Constants
|
||||||
|
***********************************************************************************************************************************/
|
||||||
|
#define DATE_TIME_REGEX "[0-9]{8}\\-[0-9]{6}"
|
||||||
|
|
||||||
|
/***********************************************************************************************************************************
|
||||||
|
Returns an anchored regex string for filtering backups based on the type (at least one type is required to be true)
|
||||||
|
***********************************************************************************************************************************/
|
||||||
|
String *
|
||||||
|
backupRegExp(BackupRegExpParam param)
|
||||||
|
{
|
||||||
|
FUNCTION_LOG_BEGIN(logLevelTrace);
|
||||||
|
FUNCTION_LOG_PARAM(BOOL, param.full);
|
||||||
|
FUNCTION_LOG_PARAM(BOOL, param.differential);
|
||||||
|
FUNCTION_LOG_PARAM(BOOL, param.incremental);
|
||||||
|
FUNCTION_LOG_END();
|
||||||
|
|
||||||
|
ASSERT(param.full || param.differential || param.incremental);
|
||||||
|
|
||||||
|
String *result = NULL;
|
||||||
|
|
||||||
|
// Start the expression with the anchor, date/time regexp and full backup indicator
|
||||||
|
result = strNew("^" DATE_TIME_REGEX "F");
|
||||||
|
|
||||||
|
// Add the diff and/or incr expressions if requested
|
||||||
|
if (param.differential || param.incremental)
|
||||||
|
{
|
||||||
|
// If full requested then diff/incr is optional
|
||||||
|
if (param.full)
|
||||||
|
{
|
||||||
|
strCat(result, "(\\_");
|
||||||
|
}
|
||||||
|
// Else diff/incr is required
|
||||||
|
else
|
||||||
|
{
|
||||||
|
strCat(result, "\\_");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Append date/time regexp for diff/incr
|
||||||
|
strCat(result, DATE_TIME_REGEX);
|
||||||
|
|
||||||
|
// Filter on both diff/incr
|
||||||
|
if (param.differential && param.incremental)
|
||||||
|
{
|
||||||
|
strCat(result, "(D|I)");
|
||||||
|
}
|
||||||
|
// Else just diff
|
||||||
|
else if (param.differential)
|
||||||
|
{
|
||||||
|
strCatChr(result, 'D');
|
||||||
|
}
|
||||||
|
// Else just incr
|
||||||
|
else
|
||||||
|
{
|
||||||
|
strCatChr(result, 'I');
|
||||||
|
}
|
||||||
|
|
||||||
|
// If full requested then diff/incr is optional
|
||||||
|
if (param.full)
|
||||||
|
{
|
||||||
|
strCat(result, "){0,1}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Append the end anchor
|
||||||
|
strCat(result, "$");
|
||||||
|
|
||||||
|
FUNCTION_LOG_RETURN(STRING, result);
|
||||||
|
}
|
26
src/command/backup/common.h
Normal file
26
src/command/backup/common.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
/***********************************************************************************************************************************
|
||||||
|
Common Functions and Definitions for Backup and Expire Commands
|
||||||
|
***********************************************************************************************************************************/
|
||||||
|
#ifndef COMMAND_BACKUP_COMMON_H
|
||||||
|
#define COMMAND_BACKUP_COMMON_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include "common/type/string.h"
|
||||||
|
|
||||||
|
/***********************************************************************************************************************************
|
||||||
|
Returns an anchored regex string for filtering backups based on the type (at least one type is required to be true)
|
||||||
|
***********************************************************************************************************************************/
|
||||||
|
typedef struct BackupRegExpParam
|
||||||
|
{
|
||||||
|
bool full;
|
||||||
|
bool differential;
|
||||||
|
bool incremental;
|
||||||
|
} BackupRegExpParam;
|
||||||
|
|
||||||
|
#define backupRegExpP(...) \
|
||||||
|
backupRegExp((BackupRegExpParam){__VA_ARGS__})
|
||||||
|
|
||||||
|
String *backupRegExp(BackupRegExpParam param);
|
||||||
|
|
||||||
|
#endif
|
@ -661,6 +661,13 @@ unit:
|
|||||||
command/archive/push/protocol: full
|
command/archive/push/protocol: full
|
||||||
command/archive/push/push: full
|
command/archive/push/push: full
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------------------------------------------------------------------
|
||||||
|
- name: backup-common
|
||||||
|
total: 1
|
||||||
|
|
||||||
|
coverage:
|
||||||
|
command/backup/common: full
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------------------------------------------------------
|
||||||
- name: command
|
- name: command
|
||||||
total: 1
|
total: 1
|
||||||
|
104
test/src/module/command/backupCommonTest.c
Normal file
104
test/src/module/command/backupCommonTest.c
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
/***********************************************************************************************************************************
|
||||||
|
Test Common Functions and Definitions for Backup and Expire Commands
|
||||||
|
***********************************************************************************************************************************/
|
||||||
|
#include "common/harnessConfig.h"
|
||||||
|
#include "storage/driver/posix/storage.h"
|
||||||
|
|
||||||
|
#include <common/regExp.h>
|
||||||
|
|
||||||
|
/***********************************************************************************************************************************
|
||||||
|
Test Run
|
||||||
|
***********************************************************************************************************************************/
|
||||||
|
void
|
||||||
|
testRun(void)
|
||||||
|
{
|
||||||
|
FUNCTION_HARNESS_VOID();
|
||||||
|
|
||||||
|
// *****************************************************************************************************************************
|
||||||
|
if (testBegin("backupRegExp()"))
|
||||||
|
{
|
||||||
|
String *full = strNew("20181119-152138F");
|
||||||
|
String *incr = strNew("20181119-152138F_20181119-152152I");
|
||||||
|
String *diff = strNew("20181119-152138F_20181119-152152D");
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------------------------------------------------------
|
||||||
|
TEST_ERROR(
|
||||||
|
backupRegExpP(0),
|
||||||
|
AssertError, "assertion 'param.full || param.differential || param.incremental' failed");
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------------------------------------------------------
|
||||||
|
String *filter = backupRegExpP(.full = true);
|
||||||
|
TEST_RESULT_STR(strPtr(filter), "^[0-9]{8}\\-[0-9]{6}F$", "full backup regex with anchors");
|
||||||
|
TEST_RESULT_BOOL(regExpMatchOne(filter, incr), false, " does not exactly match incr");
|
||||||
|
TEST_RESULT_BOOL(regExpMatchOne(filter, diff), false, " does not exactly match diff");
|
||||||
|
TEST_RESULT_BOOL(regExpMatchOne(filter, full), true, " exactly matches full");
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------------------------------------------------------
|
||||||
|
filter = backupRegExpP(.full = true, .incremental = true);
|
||||||
|
TEST_RESULT_STR(
|
||||||
|
strPtr(filter),
|
||||||
|
"^[0-9]{8}\\-[0-9]{6}F(\\_[0-9]{8}\\-[0-9]{6}I){0,1}$", "full and optional incr backup regex with anchors");
|
||||||
|
TEST_RESULT_BOOL(regExpMatchOne(filter, incr), true, " match incr");
|
||||||
|
TEST_RESULT_BOOL(regExpMatchOne(filter, diff), false, " does not match diff");
|
||||||
|
TEST_RESULT_BOOL(regExpMatchOne(filter, full), true, " match full");
|
||||||
|
TEST_RESULT_BOOL(
|
||||||
|
regExpMatchOne(
|
||||||
|
filter, strNew("12341234-123123F_12341234-123123IG")), false, " does not match with trailing character");
|
||||||
|
TEST_RESULT_BOOL(
|
||||||
|
regExpMatchOne(
|
||||||
|
filter, strNew("A12341234-123123F_12341234-123123I")), false, " does not match with leading character");
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------------------------------------------------------
|
||||||
|
filter = backupRegExpP(.full = true, .differential = true);
|
||||||
|
TEST_RESULT_STR(
|
||||||
|
strPtr(filter),
|
||||||
|
"^[0-9]{8}\\-[0-9]{6}F(\\_[0-9]{8}\\-[0-9]{6}D){0,1}$", "full and optional diff backup regex with anchors");
|
||||||
|
TEST_RESULT_BOOL(regExpMatchOne(filter, incr), false, " does not match incr");
|
||||||
|
TEST_RESULT_BOOL(regExpMatchOne(filter, diff), true, " match diff");
|
||||||
|
TEST_RESULT_BOOL(regExpMatchOne(filter, full), true, " match full");
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------------------------------------------------------
|
||||||
|
filter = backupRegExpP(.full = true, .incremental = true, .differential = true);
|
||||||
|
TEST_RESULT_STR(
|
||||||
|
strPtr(filter),
|
||||||
|
"^[0-9]{8}\\-[0-9]{6}F(\\_[0-9]{8}\\-[0-9]{6}(D|I)){0,1}$", "full, optional diff and incr backup regex with anchors");
|
||||||
|
TEST_RESULT_BOOL(regExpMatchOne(filter, incr), true, " match incr");
|
||||||
|
TEST_RESULT_BOOL(regExpMatchOne(filter, diff), true, " match diff");
|
||||||
|
TEST_RESULT_BOOL(regExpMatchOne(filter, full), true, " match full");
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------------------------------------------------------
|
||||||
|
filter = backupRegExpP(.incremental = true, .differential = true);
|
||||||
|
TEST_RESULT_STR(
|
||||||
|
strPtr(filter),
|
||||||
|
"^[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, diff), true, " match diff");
|
||||||
|
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(
|
||||||
|
regExpMatchOne(
|
||||||
|
filter, strNew("A12341234-123123F_12341234-123123I")), false, " does not match with leading character");
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------------------------------------------------------
|
||||||
|
filter = backupRegExpP(.incremental = true);
|
||||||
|
TEST_RESULT_STR(
|
||||||
|
strPtr(filter),
|
||||||
|
"^[0-9]{8}\\-[0-9]{6}F\\_[0-9]{8}\\-[0-9]{6}I$", "incr backup regex with anchors");
|
||||||
|
TEST_RESULT_BOOL(regExpMatchOne(filter, incr), true, " match incr");
|
||||||
|
TEST_RESULT_BOOL(regExpMatchOne(filter, diff), false, " does not match diff");
|
||||||
|
TEST_RESULT_BOOL(regExpMatchOne(filter, full), false, " does not match full");
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------------------------------------------------------
|
||||||
|
filter = backupRegExpP(.differential = true);
|
||||||
|
TEST_RESULT_STR(
|
||||||
|
strPtr(filter),
|
||||||
|
"^[0-9]{8}\\-[0-9]{6}F\\_[0-9]{8}\\-[0-9]{6}D$", "diff backup regex with anchors");
|
||||||
|
TEST_RESULT_BOOL(regExpMatchOne(filter, incr), false, " does not match incr");
|
||||||
|
TEST_RESULT_BOOL(regExpMatchOne(filter, diff), true, " match diff");
|
||||||
|
TEST_RESULT_BOOL(regExpMatchOne(filter, full), false, " does not match full");
|
||||||
|
}
|
||||||
|
|
||||||
|
FUNCTION_HARNESS_RESULT_VOID();
|
||||||
|
}
|
Reference in New Issue
Block a user