# HG changeset patch # User Kim Alvefur # Date 1634946787 -7200 # Node ID fceebfb28d865416bbe1bc1539e0f6f19cb1175e # Parent 7034b30101c110060cc172654d14b70afc912b57 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. diff -r 7034b30101c1 -r fceebfb28d86 plugins/mod_http_file_share.lua --- a/plugins/mod_http_file_share.lua Thu Oct 21 21:02:14 2021 +0200 +++ b/plugins/mod_http_file_share.lua Sat Oct 23 01:53:07 2021 +0200 @@ -289,6 +289,13 @@ 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