Software /
code /
prosody-modules
Changeset
6169:dcd16e349a7a
mod_storage_metronome_readonly: Fix luacheck warnings
author | Link Mauve <linkmauve@linkmauve.fr> |
---|---|
date | Mon, 27 Jan 2025 21:33:18 +0100 |
parents | 6168:62cd65205c70 |
children | 6170:ec0e9d4f2275 |
files | mod_storage_metronome_readonly/mod_storage_metronome_readonly.lua |
diffstat | 1 files changed, 28 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_storage_metronome_readonly/mod_storage_metronome_readonly.lua Mon Jan 27 21:32:08 2025 +0100 +++ b/mod_storage_metronome_readonly/mod_storage_metronome_readonly.lua Mon Jan 27 21:33:18 2025 +0100 @@ -2,7 +2,7 @@ local datetime = require "prosody.util.datetime"; local st = require "prosody.util.stanza"; local now = require "prosody.util.time".now; -local id = require "prosody.util.id".medium; +local gen_id = require "prosody.util.id".medium; local set = require "prosody.util.set"; local envloadfile = require"prosody.util.envload".envloadfile; @@ -11,7 +11,7 @@ local archive_item_limit = module:get_option_integer("storage_archive_item_limit", 10000, 0); -- Metronome doesn’t store the item publish time, so fallback to the migration time. -local when = math.floor(now()); +local time_now = math.floor(now()); local function encode (s) return s and (s:gsub("%W", function (c) return string.format("%%%02x", c:byte()); end)); @@ -59,6 +59,7 @@ end end return function() + -- luacheck: ignore 512 for node in nodes do nodes:remove(node); return node; @@ -67,7 +68,7 @@ end end -function driver:purge(user) -- luacheck: ignore 212/self +function driver:purge(user) -- luacheck: ignore 212/self user return nil, "unsupported-store"; end @@ -76,22 +77,22 @@ function keyval:get(user) if self.store == "pep" then - local data = datamanager.load(user, host, self.store); - local nodes = data["nodes"]; + local ret = datamanager.load(user, host, self.store); + local nodes = ret["nodes"]; local result = {}; local pep_base_path = datamanager.getpath(user, host, self.store):sub(1, -5); for _, node in ipairs(nodes) do local path = ("%s/%s.dat"):format(pep_base_path, encode(node)); - local data = envloadfile(path, {}); - if not data then - log("error", "Failed to load metronome storage"); + local get_data = envloadfile(path, {}); + if not get_data then + module:log("error", "Failed to load metronome storage"); return nil, "Error reading storage"; end - local success, data = pcall(data); + local success, data = pcall(get_data); if not success then - log("error", "Unable to load metronome storage"); + module:log("error", "Unable to load metronome storage"); return nil, "Error reading storage"; end local new_node = {}; @@ -103,9 +104,9 @@ end return result; elseif self.store == "cloud_notify" then - local data = datamanager.load(user, host, "push"); + local ret = datamanager.load(user, host, "push"); local result = {}; - for jid, data in pairs(data) do + for jid, data in pairs(ret) do local secret = data["secret"]; for node in pairs(data["nodes"]) do -- TODO: Does Metronome store more info than that? @@ -146,7 +147,7 @@ end end -function keyval:set(user, data) +function keyval:set(user, data) -- luacheck: ignore 212/self user data return nil, "unsupported-store"; end @@ -172,11 +173,11 @@ ids = true; }; -function archive:append(username, key, value, when, with) +function archive:append(username, key, value, when, with) -- luacheck: ignore 212/self username key value when with return nil, "unsupported-store"; end -function archive:find(username, query) +function archive:find(username, query) -- luacheck: ignore 212/self query if self.store == "archive" then local jid = username.."@"..host; local data = datamanager.load(username, host, "archiving"); @@ -225,14 +226,14 @@ local pep_base_path = datamanager.getpath(username, host, "pep"):sub(1, -5); local path = ("%s/%s.dat"):format(pep_base_path, encode(node)); - local data = envloadfile(path, {}); - if not data then - log("debug", "Failed to load metronome storage"); + local get_data = envloadfile(path, {}); + if not get_data then + module:log("debug", "Failed to load metronome storage"); return {}; end - local success, data = pcall(data); + local success, data = pcall(get_data); if not success then - log("error", "Unable to load metronome storage"); + module:log("error", "Unable to load metronome storage"); return nil, "Error reading storage"; end @@ -246,7 +247,7 @@ end local item = st.deserialize(payload[1]); local with = data["data_author"][key]; - return key, item, when, with; + return key, item, time_now, with; end; elseif self.store == "offline" then -- This is mostly copy/pasted from mod_storage_internal. @@ -273,7 +274,7 @@ end return end - local key = id(); + local key = gen_id(); local when = item.attr and datetime.parse(item.attr.stamp); local with = ""; item.key, item.when, item.with = nil, nil, nil; @@ -337,15 +338,15 @@ return nil, "item-not-found"; end -function archive:set(username, key, new_value, new_when, new_with) +function archive:set(username, key, new_value, new_when, new_with) -- luacheck: ignore 212/self username key new_value new_when new_with return nil, "unsupported-store"; end -function archive:dates(username) +function archive:dates(username) -- luacheck: ignore 212/self username return nil, "unsupported-store"; end -function archive:summary(username, query) +function archive:summary(username, query) -- luacheck: ignore 212/self username query return nil, "unsupported-store"; end @@ -384,11 +385,11 @@ end end -function archive:trim(username, to_when) +function archive:trim(username, to_when) -- luacheck: ignore 212/self username to_when return nil, "unsupported-store"; end -function archive:delete(username, query) +function archive:delete(username, query) -- luacheck: ignore 212/self username query return nil, "unsupported-store"; end