You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-07-03 00:26:59 +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:
committed by
David Steele
parent
e331564c90
commit
34898ce471
@ -33,6 +33,14 @@
|
|||||||
</release-bug-list>
|
</release-bug-list>
|
||||||
|
|
||||||
<release-improvement-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>
|
||||||
<release-item-contributor-list>
|
<release-item-contributor-list>
|
||||||
<release-item-contributor id="vondendriesch.adrian"/>
|
<release-item-contributor id="vondendriesch.adrian"/>
|
||||||
|
@ -202,13 +202,6 @@ configParse(unsigned int argListSize, const char *argList[])
|
|||||||
if (parseOptionList[optionId].reset != reset)
|
if (parseOptionList[optionId].reset != reset)
|
||||||
THROW(OptionInvalidError, "option '%s' cannot be set and reset", cfgOptionName(optionId));
|
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
|
// Add the argument
|
||||||
strLstAdd(parseOptionList[optionId].valueList, strNew(optarg));
|
strLstAdd(parseOptionList[optionId].valueList, strNew(optarg));
|
||||||
}
|
}
|
||||||
@ -437,6 +430,14 @@ configParse(unsigned int argListSize, const char *argList[])
|
|||||||
cfgCommandName(cfgCommand()));
|
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.
|
// 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));
|
cfgOptionValidSet(optionId, cfgDefOptionValid(commandDefId, optionDefId));
|
||||||
|
|
||||||
|
@ -97,6 +97,7 @@ testRun()
|
|||||||
// -------------------------------------------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------------------------------------------
|
||||||
argList = strLstNew();
|
argList = strLstNew();
|
||||||
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
||||||
|
strLstAdd(argList, strNew(TEST_COMMAND_BACKUP));
|
||||||
strLstAdd(argList, strNew("--compress-level=3"));
|
strLstAdd(argList, strNew("--compress-level=3"));
|
||||||
strLstAdd(argList, strNew("--compress-level=3"));
|
strLstAdd(argList, strNew("--compress-level=3"));
|
||||||
TEST_ERROR(
|
TEST_ERROR(
|
||||||
@ -296,6 +297,23 @@ testRun()
|
|||||||
strLstSize(argList), strLstPtr(argList)), OptionInvalidError,
|
strLstSize(argList), strLstPtr(argList)), OptionInvalidError,
|
||||||
strPtr(strNewFmt("'%s' contains duplicate options ('db-path', 'pg1-path') in section '[db]'", strPtr(configFile))));
|
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();
|
argList = strLstNew();
|
||||||
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
||||||
@ -410,7 +428,7 @@ testRun()
|
|||||||
strPtr(configFile), strPtr(configFile), strPtr(configFile), strPtr(configFile), strPtr(configFile),
|
strPtr(configFile), 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_STR(strPtr(cfgOptionStr(cfgOptPgPath)), "/path/to/db", " pg1-path is set");
|
||||||
TEST_RESULT_INT(cfgOptionSource(cfgOptPgPath), cfgSourceConfig, " pg1-path is source config");
|
TEST_RESULT_INT(cfgOptionSource(cfgOptPgPath), cfgSourceConfig, " pg1-path is source config");
|
||||||
TEST_RESULT_BOOL(cfgOptionBool(cfgOptCompress), false, " compress not is set");
|
TEST_RESULT_BOOL(cfgOptionBool(cfgOptCompress), false, " compress not is set");
|
||||||
|
Reference in New Issue
Block a user