Comparison

util/datamanager.lua @ 8013:72cfbe377326

util.datamanager: Rearrange locals
author Kim Alvefur <zash@zash.se>
date Tue, 28 Mar 2017 17:31:24 +0200
parent 8011:f8ba814fe029
child 8014:ff3787033abb
comparison
equal deleted inserted replaced
8012:e898c8fda986 8013:72cfbe377326
221 -- Append a blob of data to a file 221 -- Append a blob of data to a file
222 local function append(username, host, datastore, ext, data) 222 local function append(username, host, datastore, ext, data)
223 if type(data) ~= "string" then return; end 223 if type(data) ~= "string" then return; end
224 local filename = getpath(username, host, datastore, ext, true); 224 local filename = getpath(username, host, datastore, ext, true);
225 225
226 local ok; 226 local f = io_open(filename, "r+");
227 local f, msg, errno = io_open(filename, "r+");
228 if not f then 227 if not f then
229 return atomic_store(filename, data); 228 return atomic_store(filename, data);
230 -- File did probably not exist, let's create it 229 -- File did probably not exist, let's create it
231 end 230 end
232 231
233 local pos = f:seek("end"); 232 local pos = f:seek("end");
234 233
235 ok, msg = atomic_append(f, data); 234 local ok, msg = atomic_append(f, data);
236 235
237 if not ok then 236 if not ok then
238 f:close(); 237 f:close();
239 return ok, msg, "write"; 238 return ok, msg, "write";
240 end 239 end