1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-01-18 04:58:51 +02:00

Error when multiple arguments are set in the config file for an option that does not accept multiple arguments.

Contributed by Cynthia Shang.
This commit is contained in:
Cynthia Shang 2018-03-08 14:15:05 -05:00 committed by David Steele
parent e331564c90
commit 34898ce471
3 changed files with 35 additions and 8 deletions

View File

@ -33,6 +33,14 @@
</release-bug-list>
<release-improvement-list>
<release-item>
<release-item-contributor-list>
<release-item-contributor id="shang.cynthia"/>
</release-item-contributor-list>
<p>Error when multiple arguments are set in the config file for an option that does not accept multiple arguments.</p>
</release-item>
<release-item>
<release-item-contributor-list>
<release-item-contributor id="vondendriesch.adrian"/>

View File

@ -202,13 +202,6 @@ configParse(unsigned int argListSize, const char *argList[])
if (parseOptionList[optionId].reset != reset)
THROW(OptionInvalidError, "option '%s' cannot be set and reset", cfgOptionName(optionId));
// Error if this option does not allow multiple arguments
if (!(cfgDefOptionType(cfgOptionDefIdFromId(optionId)) == cfgDefOptTypeHash ||
cfgDefOptionType(cfgOptionDefIdFromId(optionId)) == cfgDefOptTypeList))
{
THROW(OptionInvalidError, "option '%s' cannot have multiple arguments", cfgOptionName(optionId));
}
// Add the argument
strLstAdd(parseOptionList[optionId].valueList, strNew(optarg));
}
@ -437,6 +430,14 @@ configParse(unsigned int argListSize, const char *argList[])
cfgCommandName(cfgCommand()));
}
// Error if this option does not allow multiple arguments
if (parseOption->valueList != NULL && strLstSize(parseOption->valueList) > 1 &&
!(cfgDefOptionType(cfgOptionDefIdFromId(optionId)) == cfgDefOptTypeHash ||
cfgDefOptionType(cfgOptionDefIdFromId(optionId)) == cfgDefOptTypeList))
{
THROW(OptionInvalidError, "option '%s' cannot have multiple arguments", cfgOptionName(optionId));
}
// Is the option valid for this command? If not, mark it as resolved since there is nothing more to do.
cfgOptionValidSet(optionId, cfgDefOptionValid(commandDefId, optionDefId));

View File

@ -97,6 +97,7 @@ testRun()
// -------------------------------------------------------------------------------------------------------------------------
argList = strLstNew();
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
strLstAdd(argList, strNew(TEST_COMMAND_BACKUP));
strLstAdd(argList, strNew("--compress-level=3"));
strLstAdd(argList, strNew("--compress-level=3"));
TEST_ERROR(
@ -296,6 +297,23 @@ testRun()
strLstSize(argList), strLstPtr(argList)), OptionInvalidError,
strPtr(strNewFmt("'%s' contains duplicate options ('db-path', 'pg1-path') in section '[db]'", strPtr(configFile))));
// -------------------------------------------------------------------------------------------------------------------------
argList = strLstNew();
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
strLstAdd(argList, strNew("--stanza=db"));
strLstAdd(argList, strNewFmt("--config=%s", strPtr(configFile)));
strLstAdd(argList, strNew(TEST_COMMAND_BACKUP));
storagePut(storageLocal(), configFile, bufNewStr(strNew(
"[db]\n"
"pg1-path=/path/to/db\n"
"pg1-path=/also/path/to/db\n"
)));
TEST_ERROR(configParse(strLstSize(argList), strLstPtr(argList)),
OptionInvalidError,
"option 'pg1-path' cannot have multiple arguments");
// -------------------------------------------------------------------------------------------------------------------------
argList = strLstNew();
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
@ -410,7 +428,7 @@ testRun()
strPtr(configFile), strPtr(configFile), strPtr(configFile), strPtr(configFile), strPtr(configFile),
strPtr(configFile))));
TEST_RESULT_BOOL(cfgOptionTest(cfgOptPgHost), false, " pg1-path is not set");
TEST_RESULT_BOOL(cfgOptionTest(cfgOptPgHost), false, " pg1-host is not set (command line reset override)");
TEST_RESULT_STR(strPtr(cfgOptionStr(cfgOptPgPath)), "/path/to/db", " pg1-path is set");
TEST_RESULT_INT(cfgOptionSource(cfgOptPgPath), cfgSourceConfig, " pg1-path is source config");
TEST_RESULT_BOOL(cfgOptionBool(cfgOptCompress), false, " compress not is set");