1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-17 01:12:23 +02:00

Fixed issue where --reset-* was not passing the default value to Perl.

Contributed by Cynthia Shang.
This commit is contained in:
Cynthia Shang
2018-02-13 15:58:14 -05:00
committed by David Steele
parent 213724907b
commit 00e9aca872
5 changed files with 76 additions and 58 deletions

View File

@ -2171,7 +2171,7 @@ foreach my $strKey (sort(keys(%hConfigDefine)))
{ {
$hConfigDefine{$strKey}{&CFGDEF_RESET} = true; $hConfigDefine{$strKey}{&CFGDEF_RESET} = true;
} }
elsif (!$hConfigDefine{$strKey}{&CFGDEF_RESET}) elsif (!defined($hConfigDefine{$strKey}{&CFGDEF_RESET}))
{ {
$hConfigDefine{$strKey}{&CFGDEF_RESET} = false; $hConfigDefine{$strKey}{&CFGDEF_RESET} = false;
} }

View File

@ -139,14 +139,15 @@ sub configLoad
$oOption{$strOptionName}{value} = false; $oOption{$strOptionName}{value} = false;
} }
} }
# Else reset the option
elsif ($rhOption->{$strOptionName}{reset})
{
$oOption{$strOptionName}{reset} = true;
}
# Else set the value # Else set the value
else else
{ {
# If option is reset, then indicate --reset should be prepended when passing the option to child processes
if ($rhOption->{$strOptionName}{reset})
{
$oOption{$strOptionName}{reset} = true;
}
if (defined($rhOption->{$strOptionName}{value})) if (defined($rhOption->{$strOptionName}{value}))
{ {
if (cfgDefOptionType($iOptionId) eq CFGDEF_TYPE_BOOLEAN) if (cfgDefOptionType($iOptionId) eq CFGDEF_TYPE_BOOLEAN)

View File

@ -66,69 +66,77 @@ perlOptionJson()
// If option was negated // If option was negated
if (cfgOptionNegate(optionId)) if (cfgOptionNegate(optionId))
strCatFmt(result, "\"negate\":%s", strPtr(varStrForce(varNewBool(true)))); strCatFmt(result, "\"negate\":%s", strPtr(varStrForce(varNewBool(true))));
// Else if option was reset else
else if (cfgOptionReset(optionId))
strCatFmt(result, "\"reset\":%s", strPtr(varStrForce(varNewBool(true))));
// Else not negated and has a value
else if (cfgOption(optionId) != NULL)
{ {
strCat(result, "\"value\":"); // If option is reset then add indicator
if (cfgOptionReset(optionId))
strCatFmt(result, "\"reset\":%s", strPtr(varStrForce(varNewBool(true))));
switch (cfgDefOptionType(cfgOptionDefIdFromId(optionId))) // Else not negated and has a value
if (cfgOption(optionId) != NULL)
{ {
case cfgDefOptTypeBoolean: // If option is reset, then add a comma separator before setting the value
case cfgDefOptTypeFloat: if (cfgOptionReset(optionId))
case cfgDefOptTypeInteger: strCat(result, ",");
strCat(result, "\"value\":");
switch (cfgDefOptionType(cfgOptionDefIdFromId(optionId)))
{ {
strCat(result, strPtr(varStrForce(cfgOption(optionId)))); case cfgDefOptTypeBoolean:
break; case cfgDefOptTypeFloat:
} case cfgDefOptTypeInteger:
case cfgDefOptTypeString:
{
strCatFmt(result, "\"%s\"", strPtr(cfgOptionStr(optionId)));
break;
}
case cfgDefOptTypeHash:
{
const KeyValue *valueKv = cfgOptionKv(optionId);
const VariantList *keyList = kvKeyList(valueKv);
strCat(result, "{");
for (unsigned int listIdx = 0; listIdx < varLstSize(keyList); listIdx++)
{ {
if (listIdx != 0) strCat(result, strPtr(varStrForce(cfgOption(optionId))));
strCat(result, ","); break;
strCatFmt(
result, "\"%s\":\"%s\"", strPtr(varStr(varLstGet(keyList, listIdx))),
strPtr(varStr(kvGet(valueKv, varLstGet(keyList, listIdx)))));
} }
strCat(result, "}"); case cfgDefOptTypeString:
break;
}
case cfgDefOptTypeList:
{
StringList *valueList = strLstNewVarLst(cfgOptionLst(optionId));
strCat(result, "{");
for (unsigned int listIdx = 0; listIdx < strLstSize(valueList); listIdx++)
{ {
if (listIdx != 0) strCatFmt(result, "\"%s\"", strPtr(cfgOptionStr(optionId)));
strCat(result, ","); break;
strCatFmt(result, "\"%s\":true", strPtr(strLstGet(valueList, listIdx)));
} }
strCat(result, "}"); case cfgDefOptTypeHash:
{
const KeyValue *valueKv = cfgOptionKv(optionId);
const VariantList *keyList = kvKeyList(valueKv);
break; strCat(result, "{");
for (unsigned int listIdx = 0; listIdx < varLstSize(keyList); listIdx++)
{
if (listIdx != 0)
strCat(result, ",");
strCatFmt(
result, "\"%s\":\"%s\"", strPtr(varStr(varLstGet(keyList, listIdx))),
strPtr(varStr(kvGet(valueKv, varLstGet(keyList, listIdx)))));
}
strCat(result, "}");
break;
}
case cfgDefOptTypeList:
{
StringList *valueList = strLstNewVarLst(cfgOptionLst(optionId));
strCat(result, "{");
for (unsigned int listIdx = 0; listIdx < strLstSize(valueList); listIdx++)
{
if (listIdx != 0)
strCat(result, ",");
strCatFmt(result, "\"%s\":true", strPtr(strLstGet(valueList, listIdx)));
}
strCat(result, "}");
break;
}
} }
} }
} }

View File

@ -370,6 +370,7 @@ testRun()
strLstAdd(argList, strNewFmt("--config=%s", strPtr(configFile))); strLstAdd(argList, strNewFmt("--config=%s", strPtr(configFile)));
strLstAdd(argList, strNew("--no-online")); strLstAdd(argList, strNew("--no-online"));
strLstAdd(argList, strNew("--reset-pg1-host")); strLstAdd(argList, strNew("--reset-pg1-host"));
strLstAdd(argList, strNew("--reset-backup-standby"));
strLstAdd(argList, strNew(TEST_COMMAND_BACKUP)); strLstAdd(argList, strNew(TEST_COMMAND_BACKUP));
storagePut(storageLocal(), configFile, bufNewStr(strNew( storagePut(storageLocal(), configFile, bufNewStr(strNew(
@ -384,6 +385,7 @@ testRun()
"archive-copy=y\n" "archive-copy=y\n"
"online=y\n" "online=y\n"
"pg1-path=/not/path/to/db\n" "pg1-path=/not/path/to/db\n"
"backup-standby=y\n"
"\n" "\n"
"[db:backup]\n" "[db:backup]\n"
"compress=n\n" "compress=n\n"
@ -420,6 +422,8 @@ testRun()
TEST_RESULT_INT(cfgOptionSource(cfgOptRepoHardlink), cfgSourceConfig, " repo-hardlink is source config"); TEST_RESULT_INT(cfgOptionSource(cfgOptRepoHardlink), cfgSourceConfig, " repo-hardlink is source config");
TEST_RESULT_INT(cfgOptionInt(cfgOptCompressLevel), 3, " compress-level is set"); TEST_RESULT_INT(cfgOptionInt(cfgOptCompressLevel), 3, " compress-level is set");
TEST_RESULT_INT(cfgOptionSource(cfgOptCompressLevel), cfgSourceConfig, " compress-level is source config"); TEST_RESULT_INT(cfgOptionSource(cfgOptCompressLevel), cfgSourceConfig, " compress-level is source config");
TEST_RESULT_BOOL(cfgOptionBool(cfgOptBackupStandby), false, " backup-standby not is set");
TEST_RESULT_INT(cfgOptionSource(cfgOptBackupStandby), cfgSourceDefault, " backup-standby is source default");
// ------------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------------
argList = strLstNew(); argList = strLstNew();

View File

@ -49,6 +49,10 @@ testRun()
cfgOptionValidSet(cfgOptPgHost, true); cfgOptionValidSet(cfgOptPgHost, true);
cfgOptionResetSet(cfgOptPgHost, true); cfgOptionResetSet(cfgOptPgHost, true);
cfgOptionValidSet(cfgOptBackupStandby, true);
cfgOptionResetSet(cfgOptBackupStandby, true);
cfgOptionSet(cfgOptBackupStandby, cfgSourceDefault, varNewBool(false));
cfgOptionValidSet(cfgOptProtocolTimeout, true); cfgOptionValidSet(cfgOptProtocolTimeout, true);
cfgOptionSet(cfgOptProtocolTimeout, cfgSourceParam, varNewDbl(1.1)); cfgOptionSet(cfgOptProtocolTimeout, cfgSourceParam, varNewDbl(1.1));
@ -65,6 +69,7 @@ testRun()
strPtr(strLstJoin(perlCommand(), "|")), strPtr(strLstJoin(perlCommand(), "|")),
TEST_ENV_EXE "|" TEST_PERL_EXE "|" TEST_PERL_MAIN "','backup','{" TEST_ENV_EXE "|" TEST_PERL_EXE "|" TEST_PERL_MAIN "','backup','{"
"\"archive-queue-max\":{\"source\":\"param\",\"value\":999999999999}," "\"archive-queue-max\":{\"source\":\"param\",\"value\":999999999999},"
"\"backup-standby\":{\"reset\":true,\"value\":false},"
"\"compress\":{\"source\":\"param\",\"value\":true}," "\"compress\":{\"source\":\"param\",\"value\":true},"
"\"compress-level\":{\"source\":\"config\",\"value\":3}," "\"compress-level\":{\"source\":\"config\",\"value\":3},"
"\"online\":{\"source\":\"param\",\"negate\":true}," "\"online\":{\"source\":\"param\",\"negate\":true},"