mod_http_file_share: Clean up incomplete uploads
authorKim Alvefur <zash@zash.se>
Sat, 23 Oct 2021 01:53:07 +0200
changeset 11868 fceebfb28d86
parent 11867 7034b30101c1
child 11869 77bbbd4263d7
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
--- 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