Changeset

2469:43f7637f0143

mod_http_upload: Make sure that target file does not exist prior to upload
author Kim Alvefur <zash@zash.se>
date Sun, 29 Jan 2017 17:31:28 +0100
parents 2468:3bff2848af12
children 2470:9ff809591fbc
files mod_http_upload/mod_http_upload.lua
diffstat 1 files changed, 4 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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);