Mercurial > prosody-hg
diff 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 |
line wrap: on
line diff
--- a/plugins/mod_http_file_share.lua Sat Dec 04 18:57:11 2021 +0100 +++ b/plugins/mod_http_file_share.lua Sat Sep 20 23:48:04 2025 +0200 @@ -20,6 +20,7 @@ local cache = require "prosody.util.cache"; local join_path = require "util.paths".join; local lfs = require "lfs"; +local ENOENT = require "prosody.util.pposix".ENOENT; local unknown = math.abs(0/0); local unlimited = math.huge; @@ -483,7 +484,6 @@ -- TODO HTTP DELETE to the external endpoint? local array = require "prosody.util.array"; local async = require "prosody.util.async"; - local ENOENT = require "prosody.util.pposix".ENOENT; local function sleep(t) local wait, done = async.waiter(); @@ -590,12 +590,19 @@ end local upload_dir = dm.getpath("", module.host, module.name, ""):gsub("/[^/]*$", ""); - for file in lfs.dir(upload_dir) do - local file_path = join_path(upload_dir, file); - if file ~= "." and file ~= ".." and not expected_filenames[file_path] then - local mode, err = lfs.attributes(file_path, "mode"); - module:log("warn", "Unexpected %s in upload storage: %s", mode or "file", err or file); + local upload_dir_mode, err, errno = lfs.attributes(upload_dir, "mode"); + if upload_dir_mode == "directory" then + for file in lfs.dir(upload_dir) do + local file_path = join_path(upload_dir, file); + if file ~= "." and file ~= ".." and not expected_filenames[file_path] then + local mode, err = lfs.attributes(file_path, "mode"); + module:log("warn", "Unexpected %s in upload storage: %s", mode or "file", err or file); + end end + elseif upload_dir_mode then + module:log("warn", "Unexpected type of upload directory: %s", upload_dir_mode); + elseif err and errno ~= ENOENT then + module:log("debug", "Could not determine type of upload directory: %s"); end module:log("info", "Uploaded files total: %s in %d files", B(sum), count);
