Software /
code /
prosody-modules
Comparison
mod_http_upload/mod_http_upload.lua @ 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 |
parent | 2767:e1edf643fbb1 |
child | 2947:faec53f4b31e |
comparison
equal
deleted
inserted
replaced
2799:db0f654b9b3f | 2800:8d9aed6d1f87 |
---|---|
133 elseif not check_quota(username, host, filesize) then | 133 elseif not check_quota(username, host, filesize) then |
134 module:log("debug", "Upload of %dB by %s would exceed quota", filesize, origin.full_jid); | 134 module:log("debug", "Upload of %dB by %s would exceed quota", filesize, origin.full_jid); |
135 return nil, st.error_reply(stanza, "wait", "resource-constraint", "Quota reached"); | 135 return nil, st.error_reply(stanza, "wait", "resource-constraint", "Quota reached"); |
136 end | 136 end |
137 | 137 |
138 local random_dir; | 138 local random_dir = uuid(); |
139 repeat random_dir = uuid(); | 139 local created, err = lfs.mkdir(join_path(storage_path, random_dir)); |
140 until lfs.mkdir(join_path(storage_path, random_dir)) | 140 |
141 or not lfs.attributes(join_path(storage_path, random_dir, filename)) | 141 if not created then |
142 module:log("error", "Could not create directory for slot: %s", err); | |
143 return nil, st.error_reply(stanza, "wait", "internal-server-failure"); | |
144 end | |
142 | 145 |
143 local ok = datamanager.list_append(username, host, module.name, { | 146 local ok = datamanager.list_append(username, host, module.name, { |
144 filename = filename, dir = random_dir, size = filesize, time = os.time() }); | 147 filename = filename, dir = random_dir, size = filesize, time = os.time() }); |
145 | 148 |
146 if not ok then | 149 if not ok then |