Comparison

util/datamanager.lua @ 6999:0ad66d12113a

util.datamanager: Add some comments about the append function
author Kim Alvefur <zash@zash.se>
date Fri, 11 Dec 2015 20:29:55 +0100
parent 6998:86607fe755b6
child 7000:2b57f77985a3
comparison
equal deleted inserted replaced
6998:86607fe755b6 6999:0ad66d12113a
207 -- platform independent way of checking for non-exisitng files 207 -- platform independent way of checking for non-exisitng files
208 until ok; 208 until ok;
209 return true; 209 return true;
210 end 210 end
211 211
212 -- Append a blob of data to a file
212 local function append(username, host, datastore, ext, data) 213 local function append(username, host, datastore, ext, data)
213 local filename = getpath(username, host, datastore, ext, true); 214 local filename = getpath(username, host, datastore, ext, true);
214 215
215 local ok; 216 local ok;
216 local f, msg = io_open(filename, "r+"); 217 local f, msg = io_open(filename, "r+");
217 if not f then 218 if not f then
219 -- File did probably not exist, let's create it
218 f, msg = io_open(filename, "w"); 220 f, msg = io_open(filename, "w");
219 if not f then 221 if not f then
220 return nil, msg; 222 return nil, msg;
221 end 223 end
222 end 224 end
225
223 local pos = f:seek("end"); 226 local pos = f:seek("end");
224 ok, msg = fallocate(f, pos, #data); 227 ok, msg = fallocate(f, pos, #data);
225 if not ok then 228 if not ok then
226 log("warn", "fallocate() failed: %s", tostring(msg)); 229 log("warn", "fallocate() failed: %s", tostring(msg));
227 -- This doesn't work on every file system 230 -- This doesn't work on every file system