Comparison

plugins/mod_http_file_share.lua @ 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
parent 11857:e080d6aa0b3b
child 11865:77bbbd4263d7
comparison
equal deleted inserted replaced
11863:7034b30101c1 11864:fceebfb28d86
286 module:log("debug", "Preparing to receive upload into %q, expecting %s", filename, B(upload_info.filesize)); 286 module:log("debug", "Preparing to receive upload into %q, expecting %s", filename, B(upload_info.filesize));
287 local fh, err = io.open(filename.."~", "w"); 287 local fh, err = io.open(filename.."~", "w");
288 if not fh then 288 if not fh then
289 module:log("error", "Could not open file for writing: %s", err); 289 module:log("error", "Could not open file for writing: %s", err);
290 return 500; 290 return 500;
291 end
292 function event.response:on_destroy()
293 -- Clean up incomplete upload
294 if io.type(fh) == "file" then -- still open
295 fh:close();
296 os.remove(filename.."~");
297 end
291 end 298 end
292 request.body_sink = fh; 299 request.body_sink = fh;
293 if request.body == false then 300 if request.body == false then
294 if request.headers.expect == "100-continue" then 301 if request.headers.expect == "100-continue" then
295 request.conn:write("HTTP/1.1 100 Continue\r\n\r\n"); 302 request.conn:write("HTTP/1.1 100 Continue\r\n\r\n");