aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2021-03-28 15:57:15 +0200
committerKim Alvefur <zash@zash.se>2021-03-28 15:57:15 +0200
commit29a56e7747f3039119abf41bdc70e8f93da20a83 (patch)
treea5b7400d88fb31453eb1d1860e208d54b34de03d
parent8d24fc3852e1f517c52e9690f047fdf92d4da066 (diff)
downloadprosody-29a56e7747f3039119abf41bdc70e8f93da20a83.tar.gz
prosody-29a56e7747f3039119abf41bdc70e8f93da20a83.zip
mod_http_file_share: Add internal command to check files consistency
Background: Found a few files in my store that did not match the size recorded in the slot, so I needed a way to check which which those were. As it was a bit too much to type into the shell I added it here instead.
-rw-r--r--plugins/mod_http_file_share.lua18
1 files changed, 18 insertions, 0 deletions
diff --git a/plugins/mod_http_file_share.lua b/plugins/mod_http_file_share.lua
index f8ae05ae..af9cc937 100644
--- a/plugins/mod_http_file_share.lua
+++ b/plugins/mod_http_file_share.lua
@@ -18,6 +18,7 @@ local dataform = require "util.dataforms".new;
local dt = require "util.datetime";
local hi = require "util.human.units";
local cache = require "util.cache";
+local lfs = require "lfs";
local namespace = "urn:xmpp:http:upload:0";
@@ -455,6 +456,23 @@ if expiry >= 0 and not external_base_url then
end);
end
+-- Reachable from the console
+function check_files(query)
+ local issues = {};
+ local iter = assert(uploads:find(nil, query));
+ for slot_id, file in iter do
+ local filename = get_filename(slot_id);
+ local size, err = lfs.attributes(filename, "size");
+ if not size then
+ issues[filename] = err;
+ elseif tonumber(file.attr.size) ~= size then
+ issues[filename] = "file size mismatch";
+ end
+ end
+
+ return next(issues) == nil, issues;
+end
+
module:hook("iq-get/host/urn:xmpp:http:upload:0:request", handle_slot_request);
if not external_base_url then