diff mod_http_upload/mod_http_upload.lua @ 2468:3bff2848af12

mod_http_upload: Create random directory name when assigning slot
author Kim Alvefur <zash@zash.se>
date Sun, 29 Jan 2017 17:30:25 +0100
parents 290fef768a81
children 43f7637f0143
line wrap: on
line diff
--- a/mod_http_upload/mod_http_upload.lua	Sun Jan 29 17:22:37 2017 +0100
+++ b/mod_http_upload/mod_http_upload.lua	Sun Jan 29 17:30:25 2017 +0100
@@ -84,7 +84,11 @@
 	end
 	local reply = st.reply(stanza);
 	reply:tag("slot", { xmlns = xmlns_http_upload });
-	local random = uuid();
+
+	local random;
+	repeat random = uuid();
+	until lfs.mkdir(join_path(storage_path, random))
+
 	pending_slots[random.."/"..filename] = origin.full_jid;
 	local base_url = module:http_url();
 	local slot_url = url.parse(base_url);
@@ -117,11 +121,6 @@
 		module:log("warn", "Uploaded file too large %d bytes", #event.request.body);
 		return 400;
 	end
-	local dirname = join_path(storage_path, random);
-	if not lfs.mkdir(dirname) then
-		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");