Software /
code /
prosody
Changeset
11495:6d3f84148729
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.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 28 Mar 2021 15:57:15 +0200 |
parents | 11494:284c822d4c3d |
children | 11496:8bf632540197 |
files | plugins/mod_http_file_share.lua |
diffstat | 1 files changed, 18 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/mod_http_file_share.lua Sun Mar 28 14:00:21 2021 +0200 +++ b/plugins/mod_http_file_share.lua Sun Mar 28 15:57:15 2021 +0200 @@ -18,6 +18,7 @@ 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 @@ 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