Changeset

11864:fceebfb28d86

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.
author Kim Alvefur <zash@zash.se>
date Sat, 23 Oct 2021 01:53:07 +0200
parents 11863:7034b30101c1
children 11865:77bbbd4263d7
files plugins/mod_http_file_share.lua
diffstat 1 files changed, 7 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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