From: Vsevolod Stakhov Date: Thu, 5 Apr 2018 12:18:05 +0000 (+0100) Subject: [Minor] Use override_defaults from lua_util X-Git-Tag: 1.7.3~29 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4b86e84051c9e3a9eb10e188ee8bc8840e796eca;p=rspamd.git [Minor] Use override_defaults from lua_util --- diff --git a/lualib/lua_cfg_transform.lua b/lualib/lua_cfg_transform.lua index 3d863e373..4dcfd8111 100644 --- a/lualib/lua_cfg_transform.lua +++ b/lualib/lua_cfg_transform.lua @@ -15,28 +15,7 @@ limitations under the License. ]]-- local logger = require "rspamd_logger" - -local function override_defaults(def, override) - if not override then - return def - end - if not def then - return override - end - for k,v in pairs(override) do - if def[k] then - if type(v) == 'table' then - def[k] = override_defaults(def[k], v) - else - def[k] = v - end - else - def[k] = v - end - end - - return def -end +local lua_util = require "lua_util" local function is_implicit(t) local mt = getmetatable(t) @@ -134,7 +113,7 @@ local function group_transform(cfg, k, v) if not cfg.group then cfg.group = {} end if cfg.group[k] then - cfg.group[k] = override_defaults(cfg.group[k], new_group) + cfg.group[k] = lua_util.override_defaults(cfg.group[k], new_group) else cfg.group[k] = new_group end @@ -148,7 +127,7 @@ local function symbol_transform(cfg, k, v) if gr.symbols and gr.symbols[k] then -- We override group symbol with ungrouped symbol logger.infox("overriding group symbol %s in the group %s", k, gr_n) - gr.symbols[k] = override_defaults(gr.symbols[k], v) + gr.symbols[k] = lua_util.override_defaults(gr.symbols[k], v) return end end @@ -196,7 +175,7 @@ end local function convert_metric(cfg, metric) if metric.actions then - cfg.actions = override_defaults(cfg.actions, metric.actions) + cfg.actions = lua_util.override_defaults(cfg.actions, metric.actions) logger.infox("overriding actions from the legacy metric settings") end if metric.unknown_weight then diff --git a/lualib/rspamadm/rescore.lua b/lualib/rspamadm/rescore.lua index 56a92deff..231cf2ea6 100644 --- a/lualib/rspamadm/rescore.lua +++ b/lualib/rspamadm/rescore.lua @@ -383,20 +383,6 @@ local penalty_weights = { 0 } -local function override_defaults(def, override) - for k,v in pairs(override) do - if def[k] then - if type(v) == 'table' then - override_defaults(def[k], v) - else - def[k] = v - end - else - def[k] = v - end - end -end - local function get_threshold() local actions = rspamd_config:get_all_actions() @@ -409,7 +395,7 @@ end return function (args, cfg) opts = default_opts - override_defaults(opts, getopt.getopt(args, 'i:')) + opts = lua_util.override_defaults(opts, getopt.getopt(args, 'i:')) local threshold,reject_score = get_threshold() local logs = rescore_utility.get_all_logs(cfg["logdir"]) diff --git a/src/plugins/lua/neural.lua b/src/plugins/lua/neural.lua index 547751f93..89f003b2a 100644 --- a/src/plugins/lua/neural.lua +++ b/src/plugins/lua/neural.lua @@ -975,24 +975,9 @@ else end return copy end - local function override_defaults(def, override) - for k,v in pairs(override) do - if def[k] then - if type(v) == 'table' then - override_defaults(def[k], v) - else - def[k] = v - end - else - def[k] = v - end - end - end for k,r in pairs(rules) do - local def_rules = deepcopy(default_options) + local def_rules = lua_util.override_defaults(default_options, r) def_rules['redis'] = redis_params - -- Override defaults - override_defaults(def_rules, r) if not def_rules.prefix then def_rules.prefix = k