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

Add list type for options.

The hash type was being used for lists with an additional flag (`value-hash`) to indicate that it was not really a hash.
This commit is contained in:
David Steele 2017-10-30 10:50:35 -04:00
parent f57e376c44
commit 1ef27ec8c2
11 changed files with 20 additions and 65 deletions

View File

@ -81,7 +81,6 @@ use constant BLDLCL_FUNCTION_SECTION => BLDLCL_PR
use constant BLDLCL_FUNCTION_SECURE => BLDLCL_PREFIX_RULE_OPTION . 'Secure';
use constant BLDLCL_FUNCTION_TYPE => BLDLCL_PREFIX_RULE_OPTION . 'Type';
use constant BLDLCL_FUNCTION_VALID => BLDLCL_PREFIX_RULE_OPTION . 'Valid';
use constant BLDLCL_FUNCTION_VALUE_HASH => BLDLCL_PREFIX_RULE_OPTION . 'ValueHash';
####################################################################################################################################
# Build command constant maps
@ -440,14 +439,6 @@ my $rhBuild =
&BLD_PARAM => [BLDLCL_PARAM_COMMANDID, BLDLCL_PARAM_OPTIONID],
&BLD_TRUTH_DEFAULT => false,
},
&BLDLCL_FUNCTION_VALUE_HASH =>
{
&BLD_SUMMARY => 'is the option a true hash or just a list of keys?',
&BLD_RETURN_TYPE => CGEN_DATATYPE_BOOL,
&BLD_PARAM => [BLDLCL_PARAM_OPTIONID],
&BLD_TRUTH_DEFAULT => false,
},
},
},
},
@ -615,7 +606,6 @@ sub buildConfig
functionMatrix(BLDLCL_FUNCTION_SECTION, [$iOptionId], cfgRuleOptionSection($strOption));
functionMatrix(BLDLCL_FUNCTION_SECURE, [$iOptionId], cfgRuleOptionSecure($strOption));
functionMatrix(BLDLCL_FUNCTION_TYPE, [$iOptionId], $rhOptionTypeNameIdMap->{cfgRuleOptionType($strOption)});
functionMatrix(BLDLCL_FUNCTION_VALUE_HASH, [$iOptionId], cfgRuleOptionValueHash($strOption));
}
# Build lookup functions that are not implemented with switch statements

View File

@ -11,10 +11,18 @@
<release-list>
<release date="XXXX-XX-XX" version="1.26dev" title="UNDER DEVELOPMENT">
<release-core-list>
<release-refactor-list>
<release-item>
<p>Add <id>list</id> type for options. The <id>hash</id> type was being used for lists with an additional flag (`value-hash`) to indicate that it was not really a hash.</p>
</release-item>
</release-refactor-list>
</release-core-list>
<release-test-list>
<release-refactor-list>
<release-item>
<p>Update Debian/Ubuntu containers to download lastest version of <file>pip</file>.</p>
<p>Update Debian/Ubuntu containers to download latest version of <file>pip</file>.</p>
</release-item>
</release-refactor-list>
</release-test-list>

View File

@ -110,7 +110,7 @@ sub configLoad
my $strOption = $strOptionName;
if (cfgRuleOptionType($iOptionId) eq CFGOPTDEF_TYPE_HASH)
if (cfgRuleOptionType($iOptionId) eq CFGOPTDEF_TYPE_HASH || cfgRuleOptionType($iOptionId) eq CFGOPTDEF_TYPE_LIST)
{
$strOption .= '=s@';
}
@ -563,7 +563,8 @@ sub optionValidate
}
}
# Convert a list of key/value pairs to a hash
elsif (cfgRuleOptionType($iOptionId) eq CFGOPTDEF_TYPE_HASH)
elsif (cfgRuleOptionType($iOptionId) eq CFGOPTDEF_TYPE_HASH ||
cfgRuleOptionType($iOptionId) eq CFGOPTDEF_TYPE_LIST)
{
my @oValue = ();
@ -702,7 +703,8 @@ sub optionValidate
}
# Set option value
if (cfgRuleOptionType($iOptionId) eq CFGOPTDEF_TYPE_HASH && ref($strValue) eq 'ARRAY')
if (ref($strValue) eq 'ARRAY' &&
(cfgRuleOptionType($iOptionId) eq CFGOPTDEF_TYPE_HASH || cfgRuleOptionType($iOptionId) eq CFGOPTDEF_TYPE_LIST))
{
foreach my $strItem (@{$strValue})
{
@ -710,7 +712,7 @@ sub optionValidate
my $strValue;
# If the keys are expected to have values
if (cfgRuleOptionValueHash($iOptionId))
if (cfgRuleOptionType($iOptionId) eq CFGOPTDEF_TYPE_HASH)
{
# Check for = and make sure there is a least one character on each side
my $iEqualPos = index($strItem, '=');

View File

@ -409,8 +409,6 @@ use constant CFGBLDDEF_RULE_DEPEND_OPTION => 'depend-o
push @EXPORT, qw(CFGBLDDEF_RULE_DEPEND_OPTION);
use constant CFGBLDDEF_RULE_DEPEND_LIST => 'depend-list';
push @EXPORT, qw(CFGBLDDEF_RULE_DEPEND_LIST);
use constant CFGBLDDEF_RULE_HASH_VALUE => 'hash-value';
push @EXPORT, qw(CFGBLDDEF_RULE_HASH_VALUE);
use constant CFGBLDDEF_RULE_HINT => 'hint';
push @EXPORT, qw(CFGBLDDEF_RULE_HINT);
use constant CFGBLDDEF_RULE_INDEX => 'index';
@ -440,6 +438,8 @@ use constant CFGOPTDEF_TYPE_HASH => 'hash';
push @EXPORT, qw(CFGOPTDEF_TYPE_HASH);
use constant CFGOPTDEF_TYPE_INTEGER => 'integer';
push @EXPORT, qw(CFGOPTDEF_TYPE_INTEGER);
use constant CFGOPTDEF_TYPE_LIST => 'list';
push @EXPORT, qw(CFGOPTDEF_TYPE_LIST);
use constant CFGOPTDEF_TYPE_STRING => 'string';
push @EXPORT, qw(CFGOPTDEF_TYPE_STRING);
@ -1546,8 +1546,7 @@ my %hOptionRule =
&CFGOPT_DB_INCLUDE =>
{
&CFGBLDDEF_RULE_SECTION => CFGDEF_SECTION_GLOBAL,
&CFGBLDDEF_RULE_TYPE => CFGOPTDEF_TYPE_HASH,
&CFGBLDDEF_RULE_HASH_VALUE => false,
&CFGBLDDEF_RULE_TYPE => CFGOPTDEF_TYPE_LIST,
&CFGBLDDEF_RULE_REQUIRED => false,
&CFGBLDDEF_RULE_COMMAND =>
{
@ -1828,13 +1827,6 @@ foreach my $strKey (sort(keys(%hOptionRule)))
&log(ASSERT, "type is required for option '${strKey}'");
}
# Hash types by default have hash values (rather than just a boolean list)
if (!defined($hOptionRule{$strKey}{&CFGBLDDEF_RULE_HASH_VALUE}))
{
$hOptionRule{$strKey}{&CFGBLDDEF_RULE_HASH_VALUE} =
$hOptionRule{$strKey}{&CFGBLDDEF_RULE_TYPE} eq CFGOPTDEF_TYPE_HASH ? true : false;
}
# All boolean config options can be negated. Boolean command-line options must be marked for negation individually.
if ($hOptionRule{$strKey}{&CFGBLDDEF_RULE_TYPE} eq CFGOPTDEF_TYPE_BOOLEAN &&
defined($hOptionRule{$strKey}{&CFGBLDDEF_RULE_SECTION}))

View File

@ -511,16 +511,4 @@ sub cfgRuleOptionValid
push @EXPORT, qw(cfgRuleOptionValid);
####################################################################################################################################
# cfgRuleOptionValueHash - is the option a true hash or just a list of keys?
####################################################################################################################################
sub cfgRuleOptionValueHash
{
my $strOption = cfgOptionName(shift);
return $rhOptionRuleIndex->{$strOption}{&CFGBLDDEF_RULE_HASH_VALUE};
}
push @EXPORT, qw(cfgRuleOptionValueHash);
1;

View File

@ -35,7 +35,7 @@ use constant BACKREST_BIN => abs_path(
# Defines the current version of the BackRest executable. The version number is used to track features but does not affect what
# repositories or manifests can be read - that's the job of the format number.
#-----------------------------------------------------------------------------------------------------------------------------------
use constant BACKREST_VERSION => '1.25';
use constant BACKREST_VERSION => '1.26dev';
push @EXPORT, qw(BACKREST_VERSION);
# Format Format Number

View File

@ -87,7 +87,6 @@ my $rhExport =
cfgRuleOptionType
cfgRuleOptionValid
cfgOptionTotal
cfgRuleOptionValueHash
)],
},

View File

@ -121,7 +121,3 @@ cfgRuleOptionValid(commandId, optionId)
U32
cfgOptionTotal()
bool
cfgRuleOptionValueHash(optionId)
U32 optionId

View File

@ -883,7 +883,7 @@ Secure options can never be passed on the commmand-line.
| cfgRuleOptionType | `CFGOPT_COMPRESS_LEVEL` | `CFGOPTDEF_TYPE_INTEGER` |
| cfgRuleOptionType | `CFGOPT_COMPRESS_LEVEL_NETWORK` | `CFGOPTDEF_TYPE_INTEGER` |
| cfgRuleOptionType | `CFGOPT_CONFIG` | `CFGOPTDEF_TYPE_STRING` |
| cfgRuleOptionType | `CFGOPT_DB_INCLUDE` | `CFGOPTDEF_TYPE_HASH` |
| cfgRuleOptionType | `CFGOPT_DB_INCLUDE` | `CFGOPTDEF_TYPE_LIST` |
| cfgRuleOptionType | `CFGOPT_DB_TIMEOUT` | `CFGOPTDEF_TYPE_FLOAT` |
| cfgRuleOptionType | `CFGOPT_DB1_CMD` | `CFGOPTDEF_TYPE_STRING` |
| cfgRuleOptionType | `CFGOPT_DB1_CONFIG` | `CFGOPTDEF_TYPE_STRING` |
@ -1915,18 +1915,3 @@ Permutations that return `false` are excluded for brevity.
| cfgRuleOptionValid | `CFGCMD_STOP` | `CFGOPT_REPO_S3_VERIFY_SSL` | `true` |
| cfgRuleOptionValid | `CFGCMD_STOP` | `CFGOPT_REPO_TYPE` | `true` |
| cfgRuleOptionValid | `CFGCMD_STOP` | `CFGOPT_STANZA` | `true` |
## cfgRuleOptionValueHash
Is the option a true hash or just a list of keys?
### Truth Table:
Permutations that return `false` are excluded for brevity.
| Function | optionId | Result |
| -------- | -------- | ------ |
| cfgRuleOptionValueHash | `CFGOPT_LINK_MAP` | `true` |
| cfgRuleOptionValueHash | `CFGOPT_RECOVERY_OPTION` | `true` |
| cfgRuleOptionValueHash | `CFGOPT_TABLESPACE_MAP` | `true` |
| cfgRuleOptionValueHash | `CFGOPT_TEST_POINT` | `true` |

View File

@ -38,6 +38,5 @@ const char *cfgRuleOptionSection(int optionId);
bool cfgRuleOptionSecure(int optionId);
int cfgRuleOptionType(int optionId);
bool cfgRuleOptionValid(int commandId, int optionId);
bool cfgRuleOptionValueHash(int optionId);
#endif

View File

@ -23,7 +23,6 @@ void testRun()
cfgRuleOptionSection(optionId);
cfgRuleOptionSecure(optionId);
cfgRuleOptionType(optionId);
cfgRuleOptionValueHash(optionId);
for (int commandId = 0; commandId < cfgCommandTotal(); commandId++)
{
@ -161,9 +160,6 @@ void testRun()
TEST_RESULT_BOOL(cfgRuleOptionValid(CFGCMD_BACKUP, CFGOPT_TYPE), true, "option valid");
TEST_RESULT_BOOL(cfgRuleOptionValid(CFGCMD_INFO, CFGOPT_TYPE), false, "option not valid");
TEST_RESULT_BOOL(cfgRuleOptionValueHash(CFGOPT_LINK_MAP), true, "option is value hash");
TEST_RESULT_BOOL(cfgRuleOptionValueHash(CFGOPT_TYPE), false, "option is not value hash");
TEST_RESULT_STR(cfgCommandName(CFGCMD_ARCHIVE_GET), "archive-get", "command name from id");
TEST_RESULT_STR(cfgCommandName(-1), NULL, "invalid command id (lower bound)");
TEST_RESULT_STR(cfgCommandName(999999), NULL, "invalid command id (upper bound)");