mod_http_upload: Make sure that target file does not exist prior to upload
authorKim Alvefur <zash@zash.se>
Sun, 29 Jan 2017 17:31:28 +0100
changeset 2473 43f7637f0143
parent 2472 3bff2848af12
child 2474 9ff809591fbc
mod_http_upload: Make sure that target file does not exist prior to upload
mod_http_upload/mod_http_upload.lua
--- a/mod_http_upload/mod_http_upload.lua	Sun Jan 29 17:30:25 2017 +0100
+++ b/mod_http_upload/mod_http_upload.lua	Sun Jan 29 17:31:28 2017 +0100
@@ -123,6 +123,10 @@
 	end
 	pending_slots[path] = nil;
 	local full_filename = join_path(dirname, filename);
+	if lfs.attributes(full_filename) then
+		module:log("warn", "File %s exists already, not replacing it", full_filename);
+		return 409;
+	end
 	local fh, ferr = io.open(full_filename, "w");
 	if not fh then
 		module:log("error", "Could not open file %s for upload: %s", full_filename, ferr);