mod_http_upload: Only try to create a randomly named directory once.
authorKim Alvefur <zash@zash.se>
Tue, 17 Oct 2017 22:39:37 +0200
changeset 2804 8d9aed6d1f87
parent 2803 db0f654b9b3f
child 2805 cb2342cf3f3c
mod_http_upload: Only try to create a randomly named directory once.
mod_http_upload/mod_http_upload.lua
--- a/mod_http_upload/mod_http_upload.lua	Sun Oct 15 11:10:37 2017 +0200
+++ b/mod_http_upload/mod_http_upload.lua	Tue Oct 17 22:39:37 2017 +0200
@@ -135,10 +135,13 @@
 		return nil, st.error_reply(stanza, "wait", "resource-constraint", "Quota reached");
 	end
 
-	local random_dir;
-	repeat random_dir = uuid();
-	until lfs.mkdir(join_path(storage_path, random_dir))
-		or not lfs.attributes(join_path(storage_path, random_dir, filename))
+	local random_dir = uuid();
+	local created, err = lfs.mkdir(join_path(storage_path, random_dir));
+
+	if not created then
+		module:log("error", "Could not create directory for slot: %s", err);
+		return nil, st.error_reply(stanza, "wait", "internal-server-failure");
+	end
 
 	local ok = datamanager.list_append(username, host, module.name, {
 		filename = filename, dir = random_dir, size = filesize, time = os.time() });