summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2023-03-25 12:30:15 +0000
committerVsevolod Stakhov <vsevolod@rspamd.com>2023-03-25 12:30:15 +0000
commitc3646183acf81ebf630cba1615d7ebf6105ee388 (patch)
treed604ae4555e78414e73cc89b17e66cfdfd3dea9c
parent3496dd364745a2b747ae775b6a3804d4524054e5 (diff)
downloadrspamd-c3646183acf81ebf630cba1615d7ebf6105ee388.tar.gz
rspamd-c3646183acf81ebf630cba1615d7ebf6105ee388.zip
[Minor] Load redis scripts from the prefix to simplify calls
-rw-r--r--lualib/lua_redis.lua8
-rw-r--r--lualib/lua_util.lua7
2 files changed, 14 insertions, 1 deletions
diff --git a/lualib/lua_redis.lua b/lualib/lua_redis.lua
index 6f59cbc4f..76e8db972 100644
--- a/lualib/lua_redis.lua
+++ b/lualib/lua_redis.lua
@@ -1286,9 +1286,15 @@ exports.add_redis_script = add_redis_script
-- @param redis_params The Redis parameters to use for this script.
-- @return The ID of the newly added Redis script.
--
-local function load_redis_script_from_file(filename, redis_params)
+local function load_redis_script_from_file(filename, redis_params, dir)
local lua_util = require "lua_util"
local rspamd_logger = require "rspamd_logger"
+
+ if not dir then dir = rspamd_paths.LUALIBDIR end
+ if filename:sub(1, 1) ~= package.config:sub(1,1) then
+ -- Relative path
+ filename = lua_util.join_path(dir, filename)
+ end
-- Read file contents
local file = io.open(filename, "r")
if not file then
diff --git a/lualib/lua_util.lua b/lualib/lua_util.lua
index e745099a7..c2bdf40a9 100644
--- a/lualib/lua_util.lua
+++ b/lualib/lua_util.lua
@@ -1574,6 +1574,13 @@ local function join_path(...)
end
exports.join_path = join_path
+-- Short unit test for sanity
+if path_sep == '/' then
+ assert(join_path('/path', 'to', 'file') == '/path/to/file')
+else
+ assert(join_path('C:', 'path', 'to', 'file') == 'C:\\path\\to\\file')
+end
+
-- Defines symbols priorities for common usage in prefilters/postfilters
exports.symbols_priorities = {
top = 10, -- Symbols must be executed first (or last), such as settings