diff options
author | Kim Alvefur <zash@zash.se> | 2021-10-23 01:53:07 +0200 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2021-10-23 01:53:07 +0200 |
commit | 93358778981d4a5d609205f937277787210e18be (patch) | |
tree | e25ca50a4cbcf3c6f5e9eb80ffcfe81bd33b59f9 | |
parent | 7b3c41cfccd302511ced3f4cf8a1e8f0529a9d70 (diff) | |
download | prosody-93358778981d4a5d609205f937277787210e18be.tar.gz prosody-93358778981d4a5d609205f937277787210e18be.zip |
mod_http_file_share: Clean up incomplete uploads
If the request fails in the middle then the file~ could be left behind
because no code was invoked to delete it then. This gets rid of it when
the request is removed. It may still be left in case of an unclean
shutdown.
-rw-r--r-- | plugins/mod_http_file_share.lua | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/plugins/mod_http_file_share.lua b/plugins/mod_http_file_share.lua index c67a1649..f57257bb 100644 --- a/plugins/mod_http_file_share.lua +++ b/plugins/mod_http_file_share.lua @@ -289,6 +289,13 @@ function handle_upload(event, path) -- PUT /upload/:slot module:log("error", "Could not open file for writing: %s", err); return 500; end + function event.response:on_destroy() + -- Clean up incomplete upload + if io.type(fh) == "file" then -- still open + fh:close(); + os.remove(filename.."~"); + end + end request.body_sink = fh; if request.body == false then if request.headers.expect == "100-continue" then |