Changeset

2800:8d9aed6d1f87

mod_http_upload: Only try to create a randomly named directory once.
author Kim Alvefur <zash@zash.se>
date Tue, 17 Oct 2017 22:39:37 +0200
parents 2799:db0f654b9b3f
children 2801:cb2342cf3f3c
files mod_http_upload/mod_http_upload.lua
diffstat 1 files changed, 7 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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() });