Mercurial > prosody-hg
comparison plugins/mod_http_file_share.lua @ 13948:fc489086e09a
mod_http_file_share: Fix error when upload directory not created yet
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 20 Sep 2025 23:48:04 +0200 |
| parents | 0f482af5b882 |
| children | 1746a6bd4644 |
comparison
equal
deleted
inserted
replaced
| 13947:0f482af5b882 | 13948:fc489086e09a |
|---|---|
| 18 local dt = require "prosody.util.datetime"; | 18 local dt = require "prosody.util.datetime"; |
| 19 local hi = require "prosody.util.human.units"; | 19 local hi = require "prosody.util.human.units"; |
| 20 local cache = require "prosody.util.cache"; | 20 local cache = require "prosody.util.cache"; |
| 21 local join_path = require "util.paths".join; | 21 local join_path = require "util.paths".join; |
| 22 local lfs = require "lfs"; | 22 local lfs = require "lfs"; |
| 23 local ENOENT = require "prosody.util.pposix".ENOENT; | |
| 23 | 24 |
| 24 local unknown = math.abs(0/0); | 25 local unknown = math.abs(0/0); |
| 25 local unlimited = math.huge; | 26 local unlimited = math.huge; |
| 26 | 27 |
| 27 local namespace = "urn:xmpp:http:upload:0"; | 28 local namespace = "urn:xmpp:http:upload:0"; |
| 481 | 482 |
| 482 if expiry < math.huge and not external_base_url then | 483 if expiry < math.huge and not external_base_url then |
| 483 -- TODO HTTP DELETE to the external endpoint? | 484 -- TODO HTTP DELETE to the external endpoint? |
| 484 local array = require "prosody.util.array"; | 485 local array = require "prosody.util.array"; |
| 485 local async = require "prosody.util.async"; | 486 local async = require "prosody.util.async"; |
| 486 local ENOENT = require "prosody.util.pposix".ENOENT; | |
| 487 | 487 |
| 488 local function sleep(t) | 488 local function sleep(t) |
| 489 local wait, done = async.waiter(); | 489 local wait, done = async.waiter(); |
| 490 module:add_timer(t, done) | 490 module:add_timer(t, done) |
| 491 wait(); | 491 wait(); |
| 588 sum = sum + expected_size; | 588 sum = sum + expected_size; |
| 589 end | 589 end |
| 590 end | 590 end |
| 591 | 591 |
| 592 local upload_dir = dm.getpath("", module.host, module.name, ""):gsub("/[^/]*$", ""); | 592 local upload_dir = dm.getpath("", module.host, module.name, ""):gsub("/[^/]*$", ""); |
| 593 for file in lfs.dir(upload_dir) do | 593 local upload_dir_mode, err, errno = lfs.attributes(upload_dir, "mode"); |
| 594 local file_path = join_path(upload_dir, file); | 594 if upload_dir_mode == "directory" then |
| 595 if file ~= "." and file ~= ".." and not expected_filenames[file_path] then | 595 for file in lfs.dir(upload_dir) do |
| 596 local mode, err = lfs.attributes(file_path, "mode"); | 596 local file_path = join_path(upload_dir, file); |
| 597 module:log("warn", "Unexpected %s in upload storage: %s", mode or "file", err or file); | 597 if file ~= "." and file ~= ".." and not expected_filenames[file_path] then |
| 598 end | 598 local mode, err = lfs.attributes(file_path, "mode"); |
| 599 module:log("warn", "Unexpected %s in upload storage: %s", mode or "file", err or file); | |
| 600 end | |
| 601 end | |
| 602 elseif upload_dir_mode then | |
| 603 module:log("warn", "Unexpected type of upload directory: %s", upload_dir_mode); | |
| 604 elseif err and errno ~= ENOENT then | |
| 605 module:log("debug", "Could not determine type of upload directory: %s"); | |
| 599 end | 606 end |
| 600 | 607 |
| 601 module:log("info", "Uploaded files total: %s in %d files", B(sum), count); | 608 module:log("info", "Uploaded files total: %s in %d files", B(sum), count); |
| 602 if persist_stats:set(nil, "total", sum) then | 609 if persist_stats:set(nil, "total", sum) then |
| 603 total_storage_usage = sum; | 610 total_storage_usage = sum; |
