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.
--- 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