From 93358778981d4a5d609205f937277787210e18be Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 23 Oct 2021 01:53:07 +0200 Subject: 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. --- plugins/mod_http_file_share.lua | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'plugins') 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 -- cgit v1.2.3