diff mod_http_upload/mod_http_upload.lua @ 2467:290fef768a81

mod_http_upload: Forget upload slot under some error conditions
author Kim Alvefur <zash@zash.se>
date Sun, 29 Jan 2017 17:22:37 +0100
parents e822900c87d4
children 3bff2848af12
line wrap: on
line diff
--- a/mod_http_upload/mod_http_upload.lua	Sun Jan 29 16:51:25 2017 +0100
+++ b/mod_http_upload/mod_http_upload.lua	Sun Jan 29 17:22:37 2017 +0100
@@ -103,7 +103,8 @@
 
 -- http service
 local function upload_data(event, path)
-	if not pending_slots[path] then
+	local uploader = pending_slots[path];
+	if not uploader then
 		module:log("warn", "Attempt to upload to unknown slot %q", path);
 		return; -- 404
 	end
@@ -121,6 +122,7 @@
 		module:log("warn", "Could not create directory %s for upload", dirname);
 		return 500;
 	end
+	pending_slots[path] = nil;
 	local full_filename = join_path(dirname, filename);
 	local fh, ferr = io.open(full_filename, "w");
 	if not fh then
@@ -139,8 +141,7 @@
 		os.remove(full_filename);
 		return 500;
 	end
-	module:log("info", "File uploaded by %s to slot %s", pending_slots[path], random);
-	pending_slots[path] = nil;
+	module:log("info", "File uploaded by %s to slot %s", uploader, random);
 	return 200;
 end