Mercurial > prosody-hg
comparison plugins/mod_http_file_share.lua @ 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 | 77f2d45799ed |
| children | 8bf632540197 |
comparison
equal
deleted
inserted
replaced
| 11494:284c822d4c3d | 11495:6d3f84148729 |
|---|---|
| 16 local errors = require "util.error"; | 16 local errors = require "util.error"; |
| 17 local dataform = require "util.dataforms".new; | 17 local dataform = require "util.dataforms".new; |
| 18 local dt = require "util.datetime"; | 18 local dt = require "util.datetime"; |
| 19 local hi = require "util.human.units"; | 19 local hi = require "util.human.units"; |
| 20 local cache = require "util.cache"; | 20 local cache = require "util.cache"; |
| 21 local lfs = require "lfs"; | |
| 21 | 22 |
| 22 local namespace = "urn:xmpp:http:upload:0"; | 23 local namespace = "urn:xmpp:http:upload:0"; |
| 23 | 24 |
| 24 module:depends("disco"); | 25 module:depends("disco"); |
| 25 | 26 |
| 453 reaper_task:run(os.time()-expiry); | 454 reaper_task:run(os.time()-expiry); |
| 454 return 60*60; | 455 return 60*60; |
| 455 end); | 456 end); |
| 456 end | 457 end |
| 457 | 458 |
| 459 -- Reachable from the console | |
| 460 function check_files(query) | |
| 461 local issues = {}; | |
| 462 local iter = assert(uploads:find(nil, query)); | |
| 463 for slot_id, file in iter do | |
| 464 local filename = get_filename(slot_id); | |
| 465 local size, err = lfs.attributes(filename, "size"); | |
| 466 if not size then | |
| 467 issues[filename] = err; | |
| 468 elseif tonumber(file.attr.size) ~= size then | |
| 469 issues[filename] = "file size mismatch"; | |
| 470 end | |
| 471 end | |
| 472 | |
| 473 return next(issues) == nil, issues; | |
| 474 end | |
| 475 | |
| 458 module:hook("iq-get/host/urn:xmpp:http:upload:0:request", handle_slot_request); | 476 module:hook("iq-get/host/urn:xmpp:http:upload:0:request", handle_slot_request); |
| 459 | 477 |
| 460 if not external_base_url then | 478 if not external_base_url then |
| 461 module:provides("http", { | 479 module:provides("http", { |
| 462 streaming_uploads = true; | 480 streaming_uploads = true; |
