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

Add StringId as an option type.

Rather the converting String to StringIds at runtime, store defaults in StringId format in parse.auto.c and convert user input to StringId during parsing.
This commit is contained in:
David Steele 2021-11-03 07:27:26 -04:00 committed by GitHub
parent b13844086d
commit 7f6c513be9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 230 additions and 144 deletions

View File

@ -24,6 +24,9 @@
<commit subject="Use cfgOptionStrId() instead of cfgOptionStr() where appropriate.">
<github-pull-request id="1554"/>
</commit>
<commit subject="Add StringId as an option type.">
<github-pull-request id="1555"/>
</commit>
<release-item-contributor-list>
<release-item-contributor id="david.steele"/>

View File

@ -300,7 +300,7 @@ option:
main: {}
output:
type: string
type: string-id
default: text
command:
info: {}
@ -372,7 +372,7 @@ option:
main: {}
target-action:
type: string
type: string-id
default: pause
command:
restore: {}
@ -423,6 +423,7 @@ option:
main: {}
type:
type: string-id
command:
backup:
allow-list:
@ -444,7 +445,6 @@ option:
default: default
command-role:
main: {}
type: string
# Command-line only local/remote options
#---------------------------------------------------------------------------------------------------------------------------------
@ -479,7 +479,7 @@ option:
remote: {}
remote-type:
type: string
type: string-id
internal: true
required: false
allow-list:
@ -552,7 +552,7 @@ option:
main: {}
sort:
type: string
type: string-id
default: asc
allow-list:
- none
@ -686,7 +686,7 @@ option:
compress-type:
section: global
type: string
type: string-id
default: gz
allow-list:
- none
@ -959,7 +959,7 @@ option:
#---------------------------------------------------------------------------------------------------------------------------------
log-level-console:
section: global
type: string
type: string-id
default: warn
allow-list:
- off
@ -972,13 +972,13 @@ option:
log-level-file:
section: global
type: string
type: string-id
default: info
allow-list: log-level-console
log-level-stderr:
section: global
type: string
type: string-id
default: warn
allow-list: log-level-console
@ -1181,7 +1181,7 @@ option:
#---------------------------------------------------------------------------------------------------------------------------------
archive-mode:
section: global
type: string
type: string-id
default: preserve
allow-list:
- off
@ -1420,7 +1420,7 @@ option:
internal: true
section: global
group: pg
type: string
type: string-id
default: ssh
allow-list:
- ssh
@ -1602,7 +1602,7 @@ option:
repo-type:
section: global
group: repo
type: string
type: string-id
default: posix
allow-list:
- azure
@ -1714,6 +1714,7 @@ option:
repo-azure-key-type:
inherit: repo-azure-container
type: string-id
default: shared
allow-list:
- shared
@ -1722,7 +1723,7 @@ option:
repo-azure-uri-style:
section: global
group: repo
type: string
type: string-id
default: host
allow-list:
- host
@ -1745,7 +1746,7 @@ option:
repo-cipher-type:
section: global
type: string
type: string-id
group: repo
default: none
allow-list:
@ -1785,7 +1786,7 @@ option:
repo-gcs-key-type:
section: global
type: string
type: string-id
group: repo
default: service
allow-list:
@ -1814,7 +1815,7 @@ option:
internal: true
section: global
group: repo
type: string
type: string-id
default: ssh
allow-list:
- ssh
@ -1984,7 +1985,7 @@ option:
repo-retention-archive-type:
section: global
type: string
type: string-id
group: repo
default: full
allow-list:
@ -2016,7 +2017,7 @@ option:
repo-retention-full-type:
section: global
group: repo
type: string
type: string-id
default: count
allow-list:
- count
@ -2088,6 +2089,7 @@ option:
repo-s3-key-type:
inherit: repo-s3-bucket
type: string-id
default: shared
allow-list:
- shared
@ -2115,7 +2117,7 @@ option:
repo-s3-uri-style:
section: global
group: repo
type: string
type: string-id
default: host
allow-list:
- host

View File

@ -43,7 +43,7 @@ Option type constants
STRING_DECLARE(OPT_TYPE_SIZE_STR);
#define OPT_TYPE_STRING "string"
STRING_DECLARE(OPT_TYPE_STRING_STR);
#define OPT_TYPE_STRING_ID "stringId"
#define OPT_TYPE_STRING_ID "string-id"
STRING_DECLARE(OPT_TYPE_STRING_ID_STR);
#define OPT_TYPE_TIME "time"
STRING_DECLARE(OPT_TYPE_TIME_STR);

View File

@ -152,7 +152,7 @@ bldCfgRenderConfigAutoH(const Storage *const storageRepo, const BldCfg bldCfg)
{
const BldCfgOption *const opt = lstGet(bldCfg.optList, optIdx);
if (strEqZ(opt->type, CFGDEF_TYPE_STRING))
if (strEq(opt->type, OPT_TYPE_STRING_ID_STR))
{
StringList *const allowList = strLstNew();
@ -175,28 +175,27 @@ bldCfgRenderConfigAutoH(const Storage *const storageRepo, const BldCfg bldCfg)
strLstSort(allowList, sortOrderAsc);
if (!strLstEmpty(allowList))
ASSERT(!strLstEmpty(allowList));
if (lf)
strCatChr(config, '\n');
for (unsigned int allowListIdx = 0; allowListIdx < strLstSize(allowList); allowListIdx++)
{
if (lf)
strCatChr(config, '\n');
const String *const allowListItem = strLstGet(allowList, allowListIdx);
const String *const constPrefix = strUpper(
strReplaceChr(strNewFmt("CFGOPTVAL_%s_%s", strZ(opt->name), strZ(allowListItem)), '-', '_'));
for (unsigned int allowListIdx = 0; allowListIdx < strLstSize(allowList); allowListIdx++)
{
const String *const allowListItem = strLstGet(allowList, allowListIdx);
const String *const constPrefix = strUpper(
strReplaceChr(strNewFmt("CFGOPTVAL_%s_%s", strZ(opt->name), strZ(allowListItem)), '-', '_'));
// Render StringId
strCatFmt(config, "%s\n", strZ(bldDefineRender(constPrefix, bldStrId(strZ(allowListItem)))));
// Render StringId
strCatFmt(config, "%s\n", strZ(bldDefineRender(constPrefix, bldStrId(strZ(allowListItem)))));
// Render Z
strCatFmt(
config, "%s\n",
strZ(bldDefineRender(strNewFmt("%s_Z", strZ(constPrefix)), strNewFmt("\"%s\"", strZ(allowListItem)))));
}
lf = true;
// Render Z
strCatFmt(
config, "%s\n",
strZ(bldDefineRender(strNewFmt("%s_Z", strZ(constPrefix)), strNewFmt("\"%s\"", strZ(allowListItem)))));
}
lf = true;
}
}
@ -491,7 +490,7 @@ bldCfgRenderDefault(
" PARSE_RULE_OPTIONAL_DEFAULT\n"
" (\n");
if (!strEq(optType, OPT_TYPE_STRING_STR) && !strEq(optType, OPT_TYPE_PATH_STR) && !strEq(optType, OPT_TYPE_STRING_ID_STR))
if (!strEq(optType, OPT_TYPE_STRING_STR) && !strEq(optType, OPT_TYPE_PATH_STR))
strCatFmt(result, " %s,\n", strZ(bldCfgRenderScalar(defaultValue, optType)));
if (!strEq(optType, OPT_TYPE_BOOLEAN_STR))
@ -745,16 +744,6 @@ bldCfgRenderParseAutoC(const Storage *const storageRepo, const BldCfg bldCfg)
}
}
// Determine if the option has an allow list. This will decide whether it is treated as a String or StringId. This should be
// replaced with a StringId type.
bool allowList = opt->allowList != NULL;
for (unsigned int optCmdIdx = 0; optCmdIdx < lstSize(opt->cmdList); optCmdIdx++)
{
if (((BldCfgOptionCommand *)lstGet(opt->cmdList, optCmdIdx))->allowList != NULL)
allowList = true;
}
// Build default optional rules
KeyValue *const optionalDefaultRule = kvNew();
const Variant *const ruleDepend = VARSTRDEF("01-depend");
@ -787,11 +776,7 @@ bldCfgRenderParseAutoC(const Storage *const storageRepo, const BldCfg bldCfg)
if (opt->allowList != NULL)
{
kvAdd(
optionalDefaultRule, ruleAllowList,
VARSTR(
bldCfgRenderAllowList(
opt->allowList, strEq(opt->type, OPT_TYPE_STRING_STR) ? OPT_TYPE_STRING_ID_STR : opt->type)));
kvAdd(optionalDefaultRule, ruleAllowList, VARSTR(bldCfgRenderAllowList(opt->allowList, opt->type)));
for (unsigned int allowIdx = 0; allowIdx < strLstSize(opt->allowList); allowIdx++)
strLstAddIfMissing(ruleDataList, strLstGet(opt->allowList, allowIdx));
@ -799,12 +784,7 @@ bldCfgRenderParseAutoC(const Storage *const storageRepo, const BldCfg bldCfg)
if (opt->defaultValue != NULL)
{
kvAdd(
optionalDefaultRule, ruleDefault,
VARSTR(
bldCfgRenderDefault(
opt->defaultValue, opt->defaultLiteral,
strEq(opt->type, OPT_TYPE_STRING_STR) && allowList ? OPT_TYPE_STRING_ID_STR : opt->type)));
kvAdd(optionalDefaultRule, ruleDefault, VARSTR(bldCfgRenderDefault(opt->defaultValue, opt->defaultLiteral, opt->type)));
if (!strEq(opt->type, OPT_TYPE_BOOLEAN_STR))
{
@ -837,11 +817,7 @@ bldCfgRenderParseAutoC(const Storage *const storageRepo, const BldCfg bldCfg)
// Allow lists
if (optCmd->allowList != NULL)
{
kvAdd(
optionalCmdRuleType, ruleAllowList,
VARSTR(
bldCfgRenderAllowList(
optCmd->allowList, strEq(opt->type, OPT_TYPE_STRING_STR) ? OPT_TYPE_STRING_ID_STR : opt->type)));
kvAdd(optionalCmdRuleType, ruleAllowList, VARSTR(bldCfgRenderAllowList(optCmd->allowList, opt->type)));
for (unsigned int allowIdx = 0; allowIdx < strLstSize(optCmd->allowList); allowIdx++)
strLstAddIfMissing(ruleDataList, strLstGet(optCmd->allowList, allowIdx));
@ -852,10 +828,7 @@ bldCfgRenderParseAutoC(const Storage *const storageRepo, const BldCfg bldCfg)
{
kvAdd(
optionalCmdRuleType, ruleDefault,
VARSTR(
bldCfgRenderDefault(
optCmd->defaultValue, opt->defaultLiteral,
strEq(opt->type, OPT_TYPE_STRING_STR) && allowList ? OPT_TYPE_STRING_ID_STR : opt->type)));
VARSTR(bldCfgRenderDefault(optCmd->defaultValue, opt->defaultLiteral, opt->type)));
if (!strEq(opt->type, OPT_TYPE_BOOLEAN_STR))
{
@ -1003,10 +976,11 @@ bldCfgRenderParseAutoC(const Storage *const storageRepo, const BldCfg bldCfg)
if (strEq(opt->type, OPT_TYPE_STRING_STR) || strEq(opt->type, OPT_TYPE_PATH_STR))
{
if (allowList)
ruleAddList = ruleStrIdList;
else
ruleAddList = ruleStrList;
ruleAddList = ruleStrList;
}
else if (strEq(opt->type, OPT_TYPE_STRING_ID_STR))
{
ruleAddList = ruleStrIdList;
}
else
{
@ -1017,19 +991,20 @@ bldCfgRenderParseAutoC(const Storage *const storageRepo, const BldCfg bldCfg)
for (unsigned int ruleDataIdx = 0; ruleDataIdx < strLstSize(ruleDataList); ruleDataIdx++)
{
if (ruleInt)
{
strLstAddIfMissing(ruleAddList, strNewFmt("%20s", strZ(strLstGet(ruleDataList, ruleDataIdx))));
}
else if (strEq(opt->type, OPT_TYPE_STRING_ID_STR))
{
strLstAddIfMissing(ruleAddList, strLstGet(ruleDataList, ruleDataIdx));
}
else
{
if (allowList)
strLstAddIfMissing(ruleAddList, strLstGet(ruleDataList, ruleDataIdx));
else
{
strLstAddIfMissing(
ruleAddList,
strNewFmt(
"%s%s%s", opt->defaultLiteral ? "" : "\"", strZ(strLstGet(ruleDataList, ruleDataIdx)),
opt->defaultLiteral ? "" : "\""));
}
strLstAddIfMissing(
ruleAddList,
strNewFmt(
"%s%s%s", opt->defaultLiteral ? "" : "\"", strZ(strLstGet(ruleDataList, ruleDataIdx)),
opt->defaultLiteral ? "" : "\""));
}
}
}

View File

@ -430,7 +430,7 @@ backupBuildIncrPrior(const InfoBackup *infoBackup)
else
{
LOG_WARN_FMT("no prior backup exists, %s backup has been changed to full", strZ(cfgOptionDisplay(cfgOptType)));
cfgOptionSet(cfgOptType, cfgSourceParam, VARSTR(strIdToStr(backupTypeFull)));
cfgOptionSet(cfgOptType, cfgSourceParam, VARUINT64(backupTypeFull));
}
}
MEM_CONTEXT_TEMP_END();

View File

@ -456,6 +456,10 @@ cfgOptionDisplayVar(const Variant *const value, const ConfigOptionType optionTyp
{
FUNCTION_TEST_RETURN(strNewDbl((double)varInt64(value) / MSEC_PER_SEC));
}
else if (optionType == cfgOptTypeStringId)
{
FUNCTION_TEST_RETURN(strIdToStr(varUInt64(value)));
}
FUNCTION_TEST_RETURN(varStrForce(value));
}
@ -773,6 +777,9 @@ cfgOptionIdxVar(const ConfigOption optionId, const unsigned int optionIdx)
case cfgOptDataTypeList:
FUNCTION_TEST_RETURN(varNewVarLst(configLocal->option[optionId].index[optionIdx].value.list));
case cfgOptDataTypeStringId:
FUNCTION_TEST_RETURN(varNewUInt64(configLocal->option[optionId].index[optionIdx].value.stringId));
default:
ASSERT(configLocal->option[optionId].dataType == cfgOptDataTypeString);
break;
@ -924,10 +931,7 @@ cfgOptionIdxStrId(ConfigOption optionId, unsigned int optionIdx)
FUNCTION_LOG_PARAM(UINT, optionIdx);
FUNCTION_LOG_END();
// At some point the config parser will work with StringIds directly and strIdFromStr() will be removed, but for now it protects
// the callers from this logic and hopefully means no changes to the callers when the parser is updated.
FUNCTION_LOG_RETURN(
STRING_ID, strIdFromStr(cfgOptionIdxInternal(optionId, optionIdx, cfgOptDataTypeString, false)->value.string));
FUNCTION_LOG_RETURN(STRING_ID, cfgOptionIdxInternal(optionId, optionIdx, cfgOptDataTypeStringId, false)->value.stringId);
}
/**********************************************************************************************************************************/
@ -997,6 +1001,16 @@ cfgOptionIdxSet(ConfigOption optionId, unsigned int optionIdx, ConfigSource sour
break;
}
case cfgOptDataTypeStringId:
{
if (varType(value) == varTypeUInt64)
configLocal->option[optionId].index[optionIdx].value.stringId = varUInt64(value);
else
configLocal->option[optionId].index[optionIdx].value.stringId = strIdFromStr(varStr(value));
break;
}
default:
THROW_FMT(AssertError, "set not available for option data type %u", configLocal->option[optionId].dataType);
}

View File

@ -28,6 +28,7 @@ typedef union ConfigOptionValueType
const KeyValue *keyValue; // KeyValue
const VariantList *list; // VariantList
const String *string; // String
StringId stringId; // StringId
} ConfigOptionValueType;
typedef struct ConfigOptionValue

View File

@ -327,7 +327,7 @@ cfgLoadUpdateOption(void)
// Set compress-type to none. Eventually the compress option will be deprecated and removed so this reduces code churn
// when that happens.
if (!cfgOptionBool(cfgOptCompress) && cfgOptionSource(cfgOptCompressType) == cfgSourceDefault)
cfgOptionSet(cfgOptCompressType, cfgSourceParam, VARSTR(compressTypeStr(compressTypeNone)));
cfgOptionSet(cfgOptCompressType, cfgSourceParam, VARUINT64(CFGOPTVAL_COMPRESS_TYPE_NONE));
}
// Now invalidate compress so it can't be used and won't be passed to child processes
@ -385,7 +385,7 @@ cfgLoadLogFile(void)
// Attempt to open log file
if (!logFileSet(strZ(logFile)))
cfgOptionSet(cfgOptLogLevelFile, cfgSourceParam, varNewStrZ("off"));
cfgOptionSet(cfgOptLogLevelFile, cfgSourceParam, VARUINT64(CFGOPTVAL_LOG_LEVEL_CONSOLE_OFF));
}
MEM_CONTEXT_TEMP_END();
}

View File

@ -890,7 +890,7 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
PARSE_RULE_OPTION
(
PARSE_RULE_OPTION_NAME("archive-mode"),
PARSE_RULE_OPTION_TYPE(cfgOptTypeString),
PARSE_RULE_OPTION_TYPE(cfgOptTypeStringId),
PARSE_RULE_OPTION_RESET(true),
PARSE_RULE_OPTION_REQUIRED(true),
PARSE_RULE_OPTION_SECTION(cfgSectionGlobal),
@ -912,6 +912,7 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
PARSE_RULE_OPTIONAL_DEFAULT
(
PARSE_RULE_VAL_STRID(parseRuleValStrIdPreserve),
PARSE_RULE_VAL_STR(parseRuleValStrQT_preserve_QT),
),
),
@ -1354,7 +1355,7 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
PARSE_RULE_OPTION
(
PARSE_RULE_OPTION_NAME("compress-type"),
PARSE_RULE_OPTION_TYPE(cfgOptTypeString),
PARSE_RULE_OPTION_TYPE(cfgOptTypeStringId),
PARSE_RULE_OPTION_RESET(true),
PARSE_RULE_OPTION_REQUIRED(true),
PARSE_RULE_OPTION_SECTION(cfgSectionGlobal),
@ -1385,6 +1386,7 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
PARSE_RULE_OPTIONAL_DEFAULT
(
PARSE_RULE_VAL_STRID(parseRuleValStrIdGz),
PARSE_RULE_VAL_STR(parseRuleValStrQT_gz_QT),
),
),
@ -2320,7 +2322,7 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
PARSE_RULE_OPTION
(
PARSE_RULE_OPTION_NAME("log-level-console"),
PARSE_RULE_OPTION_TYPE(cfgOptTypeString),
PARSE_RULE_OPTION_TYPE(cfgOptTypeStringId),
PARSE_RULE_OPTION_RESET(true),
PARSE_RULE_OPTION_REQUIRED(true),
PARSE_RULE_OPTION_SECTION(cfgSectionGlobal),
@ -2400,6 +2402,7 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
PARSE_RULE_OPTIONAL_DEFAULT
(
PARSE_RULE_VAL_STRID(parseRuleValStrIdWarn),
PARSE_RULE_VAL_STR(parseRuleValStrQT_warn_QT),
),
),
@ -2410,7 +2413,7 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
PARSE_RULE_OPTION
(
PARSE_RULE_OPTION_NAME("log-level-file"),
PARSE_RULE_OPTION_TYPE(cfgOptTypeString),
PARSE_RULE_OPTION_TYPE(cfgOptTypeStringId),
PARSE_RULE_OPTION_RESET(true),
PARSE_RULE_OPTION_REQUIRED(true),
PARSE_RULE_OPTION_SECTION(cfgSectionGlobal),
@ -2490,6 +2493,7 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
PARSE_RULE_OPTIONAL_DEFAULT
(
PARSE_RULE_VAL_STRID(parseRuleValStrIdInfo),
PARSE_RULE_VAL_STR(parseRuleValStrQT_info_QT),
),
),
@ -2500,7 +2504,7 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
PARSE_RULE_OPTION
(
PARSE_RULE_OPTION_NAME("log-level-stderr"),
PARSE_RULE_OPTION_TYPE(cfgOptTypeString),
PARSE_RULE_OPTION_TYPE(cfgOptTypeStringId),
PARSE_RULE_OPTION_RESET(true),
PARSE_RULE_OPTION_REQUIRED(true),
PARSE_RULE_OPTION_SECTION(cfgSectionGlobal),
@ -2580,6 +2584,7 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
PARSE_RULE_OPTIONAL_DEFAULT
(
PARSE_RULE_VAL_STRID(parseRuleValStrIdWarn),
PARSE_RULE_VAL_STR(parseRuleValStrQT_warn_QT),
),
),
@ -2961,7 +2966,7 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
PARSE_RULE_OPTION
(
PARSE_RULE_OPTION_NAME("output"),
PARSE_RULE_OPTION_TYPE(cfgOptTypeString),
PARSE_RULE_OPTION_TYPE(cfgOptTypeStringId),
PARSE_RULE_OPTION_REQUIRED(true),
PARSE_RULE_OPTION_SECTION(cfgSectionCommandLine),
@ -2983,6 +2988,7 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
PARSE_RULE_OPTIONAL_DEFAULT
(
PARSE_RULE_VAL_STRID(parseRuleValStrIdText),
PARSE_RULE_VAL_STR(parseRuleValStrQT_text_QT),
),
),
@ -3526,7 +3532,7 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
PARSE_RULE_OPTION
(
PARSE_RULE_OPTION_NAME("pg-host-type"),
PARSE_RULE_OPTION_TYPE(cfgOptTypeString),
PARSE_RULE_OPTION_TYPE(cfgOptTypeStringId),
PARSE_RULE_OPTION_RESET(true),
PARSE_RULE_OPTION_REQUIRED(true),
PARSE_RULE_OPTION_SECTION(cfgSectionGlobal),
@ -3577,6 +3583,7 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
PARSE_RULE_OPTIONAL_DEFAULT
(
PARSE_RULE_VAL_STRID(parseRuleValStrIdSsh),
PARSE_RULE_VAL_STR(parseRuleValStrQT_ssh_QT),
),
),
@ -4152,7 +4159,7 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
PARSE_RULE_OPTION
(
PARSE_RULE_OPTION_NAME("remote-type"),
PARSE_RULE_OPTION_TYPE(cfgOptTypeString),
PARSE_RULE_OPTION_TYPE(cfgOptTypeStringId),
PARSE_RULE_OPTION_REQUIRED(false),
PARSE_RULE_OPTION_SECTION(cfgSectionCommandLine),
@ -4585,7 +4592,7 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
PARSE_RULE_OPTION
(
PARSE_RULE_OPTION_NAME("repo-azure-key-type"),
PARSE_RULE_OPTION_TYPE(cfgOptTypeString),
PARSE_RULE_OPTION_TYPE(cfgOptTypeStringId),
PARSE_RULE_OPTION_RESET(true),
PARSE_RULE_OPTION_REQUIRED(true),
PARSE_RULE_OPTION_SECTION(cfgSectionGlobal),
@ -4663,6 +4670,7 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
PARSE_RULE_OPTIONAL_DEFAULT
(
PARSE_RULE_VAL_STRID(parseRuleValStrIdShared),
PARSE_RULE_VAL_STR(parseRuleValStrQT_shared_QT),
),
),
@ -4673,7 +4681,7 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
PARSE_RULE_OPTION
(
PARSE_RULE_OPTION_NAME("repo-azure-uri-style"),
PARSE_RULE_OPTION_TYPE(cfgOptTypeString),
PARSE_RULE_OPTION_TYPE(cfgOptTypeStringId),
PARSE_RULE_OPTION_RESET(true),
PARSE_RULE_OPTION_REQUIRED(true),
PARSE_RULE_OPTION_SECTION(cfgSectionGlobal),
@ -4751,6 +4759,7 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
PARSE_RULE_OPTIONAL_DEFAULT
(
PARSE_RULE_VAL_STRID(parseRuleValStrIdHost),
PARSE_RULE_VAL_STR(parseRuleValStrQT_host_QT),
),
),
@ -4840,7 +4849,7 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
PARSE_RULE_OPTION
(
PARSE_RULE_OPTION_NAME("repo-cipher-type"),
PARSE_RULE_OPTION_TYPE(cfgOptTypeString),
PARSE_RULE_OPTION_TYPE(cfgOptTypeStringId),
PARSE_RULE_OPTION_RESET(true),
PARSE_RULE_OPTION_REQUIRED(true),
PARSE_RULE_OPTION_SECTION(cfgSectionGlobal),
@ -4913,6 +4922,7 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
PARSE_RULE_OPTIONAL_DEFAULT
(
PARSE_RULE_VAL_STRID(parseRuleValStrIdNone),
PARSE_RULE_VAL_STR(parseRuleValStrQT_none_QT),
),
),
@ -5159,7 +5169,7 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
PARSE_RULE_OPTION
(
PARSE_RULE_OPTION_NAME("repo-gcs-key-type"),
PARSE_RULE_OPTION_TYPE(cfgOptTypeString),
PARSE_RULE_OPTION_TYPE(cfgOptTypeStringId),
PARSE_RULE_OPTION_RESET(true),
PARSE_RULE_OPTION_REQUIRED(true),
PARSE_RULE_OPTION_SECTION(cfgSectionGlobal),
@ -5238,6 +5248,7 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
PARSE_RULE_OPTIONAL_DEFAULT
(
PARSE_RULE_VAL_STRID(parseRuleValStrIdService),
PARSE_RULE_VAL_STR(parseRuleValStrQT_service_QT),
),
),
@ -5878,7 +5889,7 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
PARSE_RULE_OPTION
(
PARSE_RULE_OPTION_NAME("repo-host-type"),
PARSE_RULE_OPTION_TYPE(cfgOptTypeString),
PARSE_RULE_OPTION_TYPE(cfgOptTypeStringId),
PARSE_RULE_OPTION_RESET(true),
PARSE_RULE_OPTION_REQUIRED(true),
PARSE_RULE_OPTION_SECTION(cfgSectionGlobal),
@ -5938,6 +5949,7 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
PARSE_RULE_OPTIONAL_DEFAULT
(
PARSE_RULE_VAL_STRID(parseRuleValStrIdSsh),
PARSE_RULE_VAL_STR(parseRuleValStrQT_ssh_QT),
),
),
@ -6176,7 +6188,7 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
PARSE_RULE_OPTION
(
PARSE_RULE_OPTION_NAME("repo-retention-archive-type"),
PARSE_RULE_OPTION_TYPE(cfgOptTypeString),
PARSE_RULE_OPTION_TYPE(cfgOptTypeStringId),
PARSE_RULE_OPTION_RESET(true),
PARSE_RULE_OPTION_REQUIRED(true),
PARSE_RULE_OPTION_SECTION(cfgSectionGlobal),
@ -6202,6 +6214,7 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
PARSE_RULE_OPTIONAL_DEFAULT
(
PARSE_RULE_VAL_STRID(parseRuleValStrIdFull),
PARSE_RULE_VAL_STR(parseRuleValStrQT_full_QT),
),
),
@ -6272,7 +6285,7 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
PARSE_RULE_OPTION
(
PARSE_RULE_OPTION_NAME("repo-retention-full-type"),
PARSE_RULE_OPTION_TYPE(cfgOptTypeString),
PARSE_RULE_OPTION_TYPE(cfgOptTypeStringId),
PARSE_RULE_OPTION_RESET(true),
PARSE_RULE_OPTION_REQUIRED(true),
PARSE_RULE_OPTION_SECTION(cfgSectionGlobal),
@ -6297,6 +6310,7 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
PARSE_RULE_OPTIONAL_DEFAULT
(
PARSE_RULE_VAL_STRID(parseRuleValStrIdCount),
PARSE_RULE_VAL_STR(parseRuleValStrQT_count_QT),
),
),
@ -6651,7 +6665,7 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
PARSE_RULE_OPTION
(
PARSE_RULE_OPTION_NAME("repo-s3-key-type"),
PARSE_RULE_OPTION_TYPE(cfgOptTypeString),
PARSE_RULE_OPTION_TYPE(cfgOptTypeStringId),
PARSE_RULE_OPTION_RESET(true),
PARSE_RULE_OPTION_REQUIRED(true),
PARSE_RULE_OPTION_SECTION(cfgSectionGlobal),
@ -6730,6 +6744,7 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
PARSE_RULE_OPTIONAL_DEFAULT
(
PARSE_RULE_VAL_STRID(parseRuleValStrIdShared),
PARSE_RULE_VAL_STR(parseRuleValStrQT_shared_QT),
),
),
@ -6973,7 +6988,7 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
PARSE_RULE_OPTION
(
PARSE_RULE_OPTION_NAME("repo-s3-uri-style"),
PARSE_RULE_OPTION_TYPE(cfgOptTypeString),
PARSE_RULE_OPTION_TYPE(cfgOptTypeStringId),
PARSE_RULE_OPTION_RESET(true),
PARSE_RULE_OPTION_REQUIRED(true),
PARSE_RULE_OPTION_SECTION(cfgSectionGlobal),
@ -7051,6 +7066,7 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
PARSE_RULE_OPTIONAL_DEFAULT
(
PARSE_RULE_VAL_STRID(parseRuleValStrIdHost),
PARSE_RULE_VAL_STR(parseRuleValStrQT_host_QT),
),
),
@ -7472,7 +7488,7 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
PARSE_RULE_OPTION
(
PARSE_RULE_OPTION_NAME("repo-type"),
PARSE_RULE_OPTION_TYPE(cfgOptTypeString),
PARSE_RULE_OPTION_TYPE(cfgOptTypeStringId),
PARSE_RULE_OPTION_RESET(true),
PARSE_RULE_OPTION_REQUIRED(true),
PARSE_RULE_OPTION_SECTION(cfgSectionGlobal),
@ -7548,6 +7564,7 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
PARSE_RULE_OPTIONAL_DEFAULT
(
PARSE_RULE_VAL_STRID(parseRuleValStrIdPosix),
PARSE_RULE_VAL_STR(parseRuleValStrQT_posix_QT),
),
),
@ -7789,7 +7806,7 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
PARSE_RULE_OPTION
(
PARSE_RULE_OPTION_NAME("sort"),
PARSE_RULE_OPTION_TYPE(cfgOptTypeString),
PARSE_RULE_OPTION_TYPE(cfgOptTypeStringId),
PARSE_RULE_OPTION_REQUIRED(true),
PARSE_RULE_OPTION_SECTION(cfgSectionCommandLine),
@ -7811,6 +7828,7 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
PARSE_RULE_OPTIONAL_DEFAULT
(
PARSE_RULE_VAL_STRID(parseRuleValStrIdAsc),
PARSE_RULE_VAL_STR(parseRuleValStrQT_asc_QT),
),
),
@ -8081,7 +8099,7 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
PARSE_RULE_OPTION
(
PARSE_RULE_OPTION_NAME("target-action"),
PARSE_RULE_OPTION_TYPE(cfgOptTypeString),
PARSE_RULE_OPTION_TYPE(cfgOptTypeStringId),
PARSE_RULE_OPTION_REQUIRED(true),
PARSE_RULE_OPTION_SECTION(cfgSectionCommandLine),
@ -8113,6 +8131,7 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
PARSE_RULE_OPTIONAL_DEFAULT
(
PARSE_RULE_VAL_STRID(parseRuleValStrIdPause),
PARSE_RULE_VAL_STR(parseRuleValStrQT_pause_QT),
),
),
@ -8561,7 +8580,7 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
PARSE_RULE_OPTION
(
PARSE_RULE_OPTION_NAME("type"),
PARSE_RULE_OPTION_TYPE(cfgOptTypeString),
PARSE_RULE_OPTION_TYPE(cfgOptTypeStringId),
PARSE_RULE_OPTION_REQUIRED(true),
PARSE_RULE_OPTION_SECTION(cfgSectionCommandLine),
@ -8589,6 +8608,7 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
PARSE_RULE_OPTIONAL_DEFAULT
(
PARSE_RULE_VAL_STRID(parseRuleValStrIdIncr),
PARSE_RULE_VAL_STR(parseRuleValStrQT_incr_QT),
),
),
@ -8615,6 +8635,7 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
PARSE_RULE_OPTIONAL_DEFAULT
(
PARSE_RULE_VAL_STRID(parseRuleValStrIdDefault),
PARSE_RULE_VAL_STR(parseRuleValStrQT_default_QT),
),
),

View File

@ -117,7 +117,7 @@ Define how an option is parsed and interacts with other options
typedef struct ParseRuleOption
{
const char *name; // Name
unsigned int type:3; // e.g. string, int, boolean
unsigned int type:4; // e.g. string, int, boolean
bool negate:1; // Can the option be negated on the command line?
bool reset:1; // Can the option be reset on the command line?
bool required:1; // Is the option required?
@ -687,6 +687,9 @@ cfgParseOptionDataType(const ConfigOption optionId)
case cfgOptTypeList:
FUNCTION_TEST_RETURN(cfgOptDataTypeList);
case cfgOptTypeStringId:
FUNCTION_TEST_RETURN(cfgOptDataTypeStringId);
default:
break;
}
@ -747,9 +750,6 @@ cfgParseOptionalFilterDepend(PackRead *const filter, const Config *const config,
// If a depend list exists, make sure the value is in the list
if (pckReadNext(filter))
{
const StringId dependValueStrId = cfgParseOptionDataType(dependId) == cfgOptDataTypeString ?
strIdFromStr(dependValue->value.string) : 0;
do
{
switch (cfgParseOptionDataType(dependId))
@ -760,9 +760,9 @@ cfgParseOptionalFilterDepend(PackRead *const filter, const Config *const config,
default:
{
ASSERT(cfgParseOptionDataType(dependId) == cfgOptDataTypeString);
ASSERT(cfgParseOptionDataType(dependId) == cfgOptDataTypeStringId);
if (parseRuleValueStrId[pckReadU32P(filter)] == dependValueStrId)
if (parseRuleValueStrId[pckReadU32P(filter)] == dependValue->value.stringId)
result = true;
break;
}
@ -962,6 +962,11 @@ cfgParseOptionalRule(
break;
}
case cfgOptTypeStringId:
optionalRules->defaultValue.stringId = parseRuleValueStrId[pckReadU32P(ruleData)];
optionalRules->defaultRaw = (const String *)&parseRuleValueStr[pckReadU32P(ruleData)];
break;
}
}
}
@ -2126,7 +2131,7 @@ configParse(const Storage *storage, unsigned int argListSize, const char *argLis
default:
{
ASSERT(cfgParseOptionDataType(dependId) == cfgOptDataTypeString);
ASSERT(cfgParseOptionDataType(dependId) == cfgOptDataTypeStringId);
String *const errorList = strNew();
unsigned int validSize = 0;
@ -2267,6 +2272,11 @@ configParse(const Storage *storage, unsigned int argListSize, const char *argLis
cfgParseOptionKeyIdxName(optionId, optionKeyIdx));
}
}
// Else if StringId
else if (optionType == cfgOptTypeStringId)
{
configOptionValue->value.stringId = strIdFromZN(strZ(valueAllow), strSize(valueAllow), false);
}
// Else if string make sure it is valid
else
{
@ -2324,13 +2334,11 @@ configParse(const Storage *storage, unsigned int argListSize, const char *argLis
PackRead *const allowList = pckReadNewC(optionalRules.allowList, optionalRules.allowListSize);
bool allowListFound = false;
if (parseRuleOption[optionId].type == cfgOptTypeString)
if (parseRuleOption[optionId].type == cfgOptTypeStringId)
{
const StringId value = strIdFromZN(strZ(valueAllow), strSize(valueAllow), false);
while (pckReadNext(allowList))
{
if (parseRuleValueStrId[pckReadU32P(allowList)] == value)
if (parseRuleValueStrId[pckReadU32P(allowList)] == configOptionValue->value.stringId)
{
allowListFound = true;
break;

View File

@ -19,6 +19,7 @@ typedef enum
cfgOptTypePath, // Path string with validation
cfgOptTypeSize, // Size, e.g. 1m, 2gb
cfgOptTypeString, // String
cfgOptTypeStringId, // StringId
cfgOptTypeTime, // Time in seconds, e.g. 23, 1.5
} ConfigOptionType;
@ -32,6 +33,7 @@ typedef enum
cfgOptDataTypeInteger, // Signed 64-bit integer
cfgOptDataTypeList, // List
cfgOptDataTypeString, // String
cfgOptDataTypeStringId, // StringId
} ConfigOptionDataType;
/***********************************************************************************************************************************

View File

@ -163,7 +163,7 @@ protocolLocalParam(ProtocolStorageType protocolStorageType, unsigned int hostIdx
// Only enable file logging on the local when requested
kvPut(
optionReplace, VARSTRDEF(CFGOPT_LOG_LEVEL_FILE),
cfgOptionBool(cfgOptLogSubprocess) ? VARSTR(cfgOptionStr(cfgOptLogLevelFile)) : VARSTRDEF("off"));
cfgOptionBool(cfgOptLogSubprocess) ? VARUINT64(cfgOptionStrId(cfgOptLogLevelFile)) : VARSTRDEF("off"));
// Always output errors on stderr for debugging purposes
kvPut(optionReplace, VARSTRDEF(CFGOPT_LOG_LEVEL_STDERR), VARSTRDEF("error"));
@ -551,7 +551,7 @@ protocolRemoteParam(ProtocolStorageType protocolStorageType, unsigned int hostId
// Only enable file logging on the remote when requested
kvPut(
optionReplace, VARSTRDEF(CFGOPT_LOG_LEVEL_FILE),
cfgOptionBool(cfgOptLogSubprocess) ? VARSTR(cfgOptionStr(cfgOptLogLevelFile)) : VARSTRDEF("off"));
cfgOptionBool(cfgOptLogSubprocess) ? VARUINT64(cfgOptionStrId(cfgOptLogLevelFile)) : VARSTRDEF("off"));
// Always output errors on stderr for debugging purposes
kvPut(optionReplace, VARSTRDEF(CFGOPT_LOG_LEVEL_STDERR), VARSTRDEF("error"));
@ -777,7 +777,7 @@ protocolRemoteGet(ProtocolStorageType protocolStorageType, unsigned int hostIdx)
VariantList *optionList = configOptionRemote(protocolHelperClient->client, param);
if (!strEq(varStr(varLstGet(optionList, 0)), strIdToStr(cipherTypeNone)))
if (varUInt64(varLstGet(optionList, 0)) != cipherTypeNone)
{
cfgOptionIdxSet(cfgOptRepoCipherType, hostIdx, cfgSourceConfig, varLstGet(optionList, 0));
cfgOptionIdxSet(cfgOptRepoCipherPass, hostIdx, cfgSourceConfig, varLstGet(optionList, 1));

View File

@ -250,6 +250,16 @@ testRun(void)
" command-role:\n"
" main: {}\n"
"\n"
" compress-network:\n"
" section: global\n"
" type: string-id\n"
" command:\n"
" backup:\n"
" allow-list:\n"
" - gz\n"
" command-role:\n"
" main: {}\n"
"\n"
" compress-type:\n"
" section: global\n"
" type: string\n"
@ -301,7 +311,7 @@ testRun(void)
"\n"
" log-level-console:\n"
" section: global\n"
" type: string\n"
" type: string-id\n"
" default: warn\n"
" allow-list:\n"
" - off\n"
@ -311,7 +321,7 @@ testRun(void)
"\n"
" log-level-file:\n"
" section: global\n"
" type: string\n"
" type: string-id\n"
" default: info\n"
" allow-list: log-level-console\n"
" command:\n"
@ -429,6 +439,7 @@ testRun(void)
"#define CFGOPT_BUFFER_SIZE \"buffer-size\"\n"
"#define CFGOPT_COMPRESS_LEVEL \"compress-level\"\n"
"#define CFGOPT_COMPRESS_LEVEL_NETWORK \"compress-level-network\"\n"
"#define CFGOPT_COMPRESS_NETWORK \"compress-network\"\n"
"#define CFGOPT_COMPRESS_TYPE \"compress-type\"\n"
"#define CFGOPT_CONFIG \"config\"\n"
"#define CFGOPT_CONFIG_INCLUDE \"config-include\"\n"
@ -438,11 +449,14 @@ testRun(void)
"#define CFGOPT_STANZA \"stanza\"\n"
"#define CFGOPT_TIMEOUT \"timeout\"\n"
"\n"
"#define CFG_OPTION_TOTAL 14\n"
"#define CFG_OPTION_TOTAL 15\n"
"\n"
COMMENT_BLOCK_BEGIN "\n"
"Option value constants\n"
COMMENT_BLOCK_END "\n"
"#define CFGOPTVAL_COMPRESS_NETWORK_GZ STRID5(\"gz\", 0x3470)\n"
"#define CFGOPTVAL_COMPRESS_NETWORK_GZ_Z \"gz\"\n"
"\n"
"#define CFGOPTVAL_LOG_LEVEL_CONSOLE_DEBUG1 STRID6(\"debug1\", 0x7475421441)\n"
"#define CFGOPTVAL_LOG_LEVEL_CONSOLE_DEBUG1_Z \"debug1\"\n"
"#define CFGOPTVAL_LOG_LEVEL_CONSOLE_ERROR STRID5(\"error\", 0x127ca450)\n"
@ -491,6 +505,7 @@ testRun(void)
" cfgOptBufferSize,\n"
" cfgOptCompressLevel,\n"
" cfgOptCompressLevelNetwork,\n"
" cfgOptCompressNetwork,\n"
" cfgOptCompressType,\n"
" cfgOptConfig,\n"
" cfgOptConfigInclude,\n"
@ -561,6 +576,7 @@ testRun(void)
"{\n"
" STRID6(\"debug1\", 0x7475421441),\n"
" STRID5(\"error\", 0x127ca450),\n"
" STRID5(\"gz\", 0x3470),\n"
" STRID5(\"info\", 0x799c90),\n"
" STRID5(\"off\", 0x18cf0),\n"
" STRID5(\"warn\", 0x748370),\n"
@ -570,6 +586,7 @@ testRun(void)
"{\n"
" parseRuleValStrIdDebug1,\n"
" parseRuleValStrIdError,\n"
" parseRuleValStrIdGz,\n"
" parseRuleValStrIdInfo,\n"
" parseRuleValStrIdOff,\n"
" parseRuleValStrIdWarn,\n"
@ -923,6 +940,37 @@ testRun(void)
COMMENT_SEPARATOR "\n"
" PARSE_RULE_OPTION\n"
" (\n"
" PARSE_RULE_OPTION_NAME(\"compress-network\"),\n"
" PARSE_RULE_OPTION_TYPE(cfgOptTypeStringId),\n"
" PARSE_RULE_OPTION_RESET(true),\n"
" PARSE_RULE_OPTION_REQUIRED(true),\n"
" PARSE_RULE_OPTION_SECTION(cfgSectionGlobal),\n"
"\n"
" PARSE_RULE_OPTION_COMMAND_ROLE_MAIN_VALID_LIST\n"
" (\n"
" PARSE_RULE_OPTION_COMMAND(cfgCmdBackup)\n"
" ),\n"
"\n"
" PARSE_RULE_OPTIONAL\n"
" (\n"
" PARSE_RULE_OPTIONAL_GROUP\n"
" (\n"
" PARSE_RULE_FILTER_CMD\n"
" (\n"
" PARSE_RULE_VAL_CMD(cfgCmdBackup),\n"
" ),\n"
"\n"
" PARSE_RULE_OPTIONAL_ALLOW_LIST\n"
" (\n"
" PARSE_RULE_VAL_STRID(parseRuleValStrIdGz),\n"
" ),\n"
" ),\n"
" ),\n"
" ),\n"
"\n"
COMMENT_SEPARATOR "\n"
" PARSE_RULE_OPTION\n"
" (\n"
" PARSE_RULE_OPTION_NAME(\"compress-type\"),\n"
" PARSE_RULE_OPTION_TYPE(cfgOptTypeString),\n"
" PARSE_RULE_OPTION_RESET(true),\n"
@ -1047,7 +1095,7 @@ testRun(void)
" PARSE_RULE_OPTION\n"
" (\n"
" PARSE_RULE_OPTION_NAME(\"log-level-console\"),\n"
" PARSE_RULE_OPTION_TYPE(cfgOptTypeString),\n"
" PARSE_RULE_OPTION_TYPE(cfgOptTypeStringId),\n"
" PARSE_RULE_OPTION_RESET(true),\n"
" PARSE_RULE_OPTION_REQUIRED(true),\n"
" PARSE_RULE_OPTION_SECTION(cfgSectionGlobal),\n"
@ -1089,6 +1137,7 @@ testRun(void)
"\n"
" PARSE_RULE_OPTIONAL_DEFAULT\n"
" (\n"
" PARSE_RULE_VAL_STRID(parseRuleValStrIdWarn),\n"
" PARSE_RULE_VAL_STR(parseRuleValStrQT_warn_QT),\n"
" ),\n"
" ),\n"
@ -1099,7 +1148,7 @@ testRun(void)
" PARSE_RULE_OPTION\n"
" (\n"
" PARSE_RULE_OPTION_NAME(\"log-level-file\"),\n"
" PARSE_RULE_OPTION_TYPE(cfgOptTypeString),\n"
" PARSE_RULE_OPTION_TYPE(cfgOptTypeStringId),\n"
" PARSE_RULE_OPTION_RESET(true),\n"
" PARSE_RULE_OPTION_REQUIRED(true),\n"
" PARSE_RULE_OPTION_SECTION(cfgSectionGlobal),\n"
@ -1149,6 +1198,7 @@ testRun(void)
"\n"
" PARSE_RULE_OPTIONAL_DEFAULT\n"
" (\n"
" PARSE_RULE_VAL_STRID(parseRuleValStrIdWarn),\n"
" PARSE_RULE_VAL_STR(parseRuleValStrQT_warn_QT),\n"
" ),\n"
"\n"
@ -1167,6 +1217,7 @@ testRun(void)
"\n"
" PARSE_RULE_OPTIONAL_DEFAULT\n"
" (\n"
" PARSE_RULE_VAL_STRID(parseRuleValStrIdInfo),\n"
" PARSE_RULE_VAL_STR(parseRuleValStrQT_info_QT),\n"
" ),\n"
" ),\n"
@ -1488,6 +1539,7 @@ testRun(void)
"{\n"
" cfgOptStanza,\n"
" cfgOptBufferSize,\n"
" cfgOptCompressNetwork,\n"
" cfgOptConfig,\n"
" cfgOptConfigInclude,\n"
" cfgOptLogLevelConsole,\n"

View File

@ -45,12 +45,12 @@ testRun(void)
TEST_TITLE("missing directory");
Buffer *output = bufNew(0);
cfgOptionSet(cfgOptOutput, cfgSourceParam, VARSTRDEF("text"));
cfgOptionSet(cfgOptOutput, cfgSourceParam, VARUINT64(CFGOPTVAL_OUTPUT_TEXT));
TEST_RESULT_VOID(storageListRender(ioBufferWriteNew(output)), "missing directory (text)");
TEST_RESULT_STR_Z(strNewBuf(output), "", "check output");
output = bufNew(0);
cfgOptionSet(cfgOptOutput, cfgSourceParam, VARSTRDEF("json"));
cfgOptionSet(cfgOptOutput, cfgSourceParam, VARUINT64(CFGOPTVAL_OUTPUT_JSON));
TEST_RESULT_VOID(storageListRender(ioBufferWriteNew(output)), "missing directory (json)");
TEST_RESULT_STR_Z(
strNewBuf(output),
@ -65,12 +65,12 @@ testRun(void)
HRN_STORAGE_PATH_CREATE(storageRepoWrite(), NULL, .mode = 0700);
output = bufNew(0);
cfgOptionSet(cfgOptOutput, cfgSourceParam, VARSTRDEF("text"));
cfgOptionSet(cfgOptOutput, cfgSourceParam, VARUINT64(CFGOPTVAL_OUTPUT_TEXT));
TEST_RESULT_VOID(storageListRender(ioBufferWriteNew(output)), "empty directory (text)");
TEST_RESULT_STR_Z(strNewBuf(output), "", "check output");
output = bufNew(0);
cfgOptionSet(cfgOptOutput, cfgSourceParam, VARSTRDEF("json"));
cfgOptionSet(cfgOptOutput, cfgSourceParam, VARUINT64(CFGOPTVAL_OUTPUT_JSON));
TEST_RESULT_VOID(storageListRender(ioBufferWriteNew(output)), "empty directory (json)");
TEST_RESULT_STR_Z(
strNewBuf(output),
@ -99,7 +99,7 @@ testRun(void)
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("add path and file");
cfgOptionSet(cfgOptSort, cfgSourceParam, VARSTRDEF("asc"));
cfgOptionSet(cfgOptSort, cfgSourceParam, VARUINT64(CFGOPTVAL_SORT_ASC));
HRN_STORAGE_PATH_CREATE(storageRepoWrite(), "bbb");
HRN_STORAGE_PUT_Z(storageRepoWrite(), "aaa", "TESTDATA", .timeModified = 1578671569);
@ -109,12 +109,12 @@ testRun(void)
HRN_SYSTEM("mkfifo " TEST_PATH "/repo/pipe");
output = bufNew(0);
cfgOptionSet(cfgOptOutput, cfgSourceParam, VARSTRDEF("text"));
cfgOptionSet(cfgOptOutput, cfgSourceParam, VARUINT64(CFGOPTVAL_OUTPUT_TEXT));
TEST_RESULT_VOID(storageListRender(ioBufferWriteNew(output)), "path and file (text)");
TEST_RESULT_STR_Z(strNewBuf(output), "aaa\nbbb\nlink\npipe\n", "check output");
output = bufNew(0);
cfgOptionSet(cfgOptOutput, cfgSourceParam, VARSTRDEF("json"));
cfgOptionSet(cfgOptOutput, cfgSourceParam, VARUINT64(CFGOPTVAL_OUTPUT_JSON));
TEST_RESULT_VOID(storageListRender(ioBufferWriteNew(output)), "path and file (json)");
TEST_RESULT_STR_Z(
strNewBuf(output),
@ -130,10 +130,10 @@ testRun(void)
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("reverse sort");
cfgOptionSet(cfgOptSort, cfgSourceParam, VARSTRDEF("desc"));
cfgOptionSet(cfgOptSort, cfgSourceParam, VARUINT64(CFGOPTVAL_SORT_DESC));
output = bufNew(0);
cfgOptionSet(cfgOptOutput, cfgSourceParam, VARSTRDEF("text"));
cfgOptionSet(cfgOptOutput, cfgSourceParam, VARUINT64(CFGOPTVAL_OUTPUT_TEXT));
TEST_RESULT_VOID(storageListRender(ioBufferWriteNew(output)), "path and file (text)");
TEST_RESULT_STR_Z(strNewBuf(output), "pipe\nlink\nbbb\naaa\n", "check output");
@ -143,7 +143,7 @@ testRun(void)
cfgOptionSet(cfgOptRecurse, cfgSourceParam, VARBOOL(true));
output = bufNew(0);
cfgOptionSet(cfgOptOutput, cfgSourceParam, VARSTRDEF("text"));
cfgOptionSet(cfgOptOutput, cfgSourceParam, VARUINT64(CFGOPTVAL_OUTPUT_TEXT));
TEST_RESULT_VOID(storageListRender(ioBufferWriteNew(output)), "filter");
TEST_RESULT_STR_Z(strNewBuf(output), "pipe\nlink\nbbb/ccc\nbbb\naaa\n", "check output");
@ -153,7 +153,7 @@ testRun(void)
cfgOptionSet(cfgOptFilter, cfgSourceParam, VARSTRDEF("^aaa$"));
output = bufNew(0);
cfgOptionSet(cfgOptOutput, cfgSourceParam, VARSTRDEF("text"));
cfgOptionSet(cfgOptOutput, cfgSourceParam, VARUINT64(CFGOPTVAL_OUTPUT_TEXT));
TEST_RESULT_VOID(storageListRender(ioBufferWriteNew(output)), "filter");
TEST_RESULT_STR_Z(strNewBuf(output), "aaa\n", "check output");
@ -165,7 +165,7 @@ testRun(void)
HRN_CFG_LOAD(cfgCmdRepoLs, argListTmp);
output = bufNew(0);
cfgOptionSet(cfgOptOutput, cfgSourceParam, VARSTRDEF("text"));
cfgOptionSet(cfgOptOutput, cfgSourceParam, VARUINT64(CFGOPTVAL_OUTPUT_TEXT));
TEST_RESULT_VOID(storageListRender(ioBufferWriteNew(output)), "subdirectory");
TEST_RESULT_STR_Z(strNewBuf(output), "ccc\n", "check output");

View File

@ -1479,7 +1479,6 @@ testRun(void)
TEST_RESULT_BOOL(cfgOptionNegate(cfgOptConfig), true, "config is negated");
TEST_RESULT_INT(cfgOptionSource(cfgOptStanza), cfgSourceParam, "stanza is source param");
TEST_RESULT_STR_Z(cfgOptionStr(cfgOptStanza), "db", "stanza is set");
TEST_RESULT_UINT(cfgOptionStrId(cfgOptStanza), strIdFromZ("db"), "stanza is set");
TEST_RESULT_INT(cfgOptionSource(cfgOptStanza), cfgSourceParam, "stanza is source param");
TEST_RESULT_STR_Z(cfgOptionIdxStr(cfgOptPgPath, 0), "/path/to/db", "pg1-path is set");
TEST_RESULT_INT(cfgOptionSource(cfgOptPgPath), cfgSourceParam, "pg1-path is source param");
@ -1642,6 +1641,9 @@ testRun(void)
TEST_RESULT_INT(cfgOptionSource(cfgOptPgPath), cfgSourceConfig, "pg1-path is source config");
TEST_RESULT_STR_Z(
cfgOptionIdxStr(cfgOptPgPath, cfgOptionKeyToIdx(cfgOptPgPath, 256)), "/path/to/db256", "pg256-path is set");
TEST_RESULT_UINT(varUInt64(cfgOptionVar(cfgOptType)), STRID5("incr", 0x90dc90), "check type");
TEST_RESULT_STR_Z(
cfgOptionDisplayVar(VARUINT64(STRID5("incr", 0x90dc90)), cfgOptTypeStringId), "incr", "check type display");
TEST_RESULT_STR_Z(cfgOptionStr(cfgOptLockPath), "/", "lock-path is set");
TEST_RESULT_INT(cfgOptionSource(cfgOptLockPath), cfgSourceConfig, "lock-path is source config");
TEST_RESULT_STR_Z(cfgOptionIdxStr(cfgOptPgSocketPath, 0), "/path/to/socket", "pg1-socket-path is set");
@ -1883,6 +1885,12 @@ testRun(void)
TEST_RESULT_VOID(cfgOptionIdxSet(cfgOptPgPath, 0, cfgSourceParam, VARSTRDEF("/new")), "set pg1-path");
TEST_RESULT_STR_Z(cfgOptionIdxStr(cfgOptPgPath, 0), "/new", "check pg1-path");
TEST_RESULT_VOID(cfgOptionIdxSet(cfgOptType, 0, cfgSourceParam, VARUINT64(STRID5("preserve", 0x2da45996500))), "set type");
TEST_RESULT_UINT(cfgOptionIdxStrId(cfgOptType, 0), STRID5("preserve", 0x2da45996500), "check type");
TEST_RESULT_VOID(cfgOptionIdxSet(cfgOptType, 0, cfgSourceParam, VARSTRDEF("standby")), "set type");
TEST_RESULT_UINT(cfgOptionIdxStrId(cfgOptType, 0), STRID5("standby", 0x6444706930), "check type");
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("stanza options should not be loaded for commands that don't take a stanza");