Comparison

mod_http_upload/mod_http_upload.lua @ 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
parent 2468:3bff2848af12
child 2470:9ff809591fbc
comparison
equal deleted inserted replaced
2468:3bff2848af12 2469:43f7637f0143
121 module:log("warn", "Uploaded file too large %d bytes", #event.request.body); 121 module:log("warn", "Uploaded file too large %d bytes", #event.request.body);
122 return 400; 122 return 400;
123 end 123 end
124 pending_slots[path] = nil; 124 pending_slots[path] = nil;
125 local full_filename = join_path(dirname, filename); 125 local full_filename = join_path(dirname, filename);
126 if lfs.attributes(full_filename) then
127 module:log("warn", "File %s exists already, not replacing it", full_filename);
128 return 409;
129 end
126 local fh, ferr = io.open(full_filename, "w"); 130 local fh, ferr = io.open(full_filename, "w");
127 if not fh then 131 if not fh then
128 module:log("error", "Could not open file %s for upload: %s", full_filename, ferr); 132 module:log("error", "Could not open file %s for upload: %s", full_filename, ferr);
129 return 500; 133 return 500;
130 end 134 end