Software /
code /
prosody
Comparison
util/datamanager.lua @ 6994:507301531cf5
util.datamanager: In append() collect status when closing file handle as it may fail (eg the implied flush)
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 11 Dec 2015 20:13:37 +0100 |
parent | 6993:dc0c6b8dc638 |
child | 6995:807b0b2ee545 |
comparison
equal
deleted
inserted
replaced
6993:dc0c6b8dc638 | 6994:507301531cf5 |
---|---|
208 until ok; | 208 until ok; |
209 return true; | 209 return true; |
210 end | 210 end |
211 | 211 |
212 local function append(username, host, datastore, ext, data) | 212 local function append(username, host, datastore, ext, data) |
213 local f, msg = io_open(getpath(username, host, datastore, ext, true), "r+"); | 213 local filename = getpath(username, host, datastore, ext, true); |
214 local f, msg = io_open(filename, "r+"); | |
214 if not f then | 215 if not f then |
215 f, msg = io_open(getpath(username, host, datastore, ext, true), "w"); | 216 f, msg = io_open(filename, "w"); |
216 end | 217 end |
217 if not f then | 218 if not f then |
218 return nil, msg; | 219 return nil, msg; |
219 end | 220 end |
220 local pos = f:seek("end"); | 221 local pos = f:seek("end"); |
223 if ok then | 224 if ok then |
224 f:write(data); | 225 f:write(data); |
225 else | 226 else |
226 return ok, msg; | 227 return ok, msg; |
227 end | 228 end |
228 f:close(); | 229 |
230 ok, msg = f:close(); | |
231 if not ok then | |
232 return ok, msg; | |
233 end | |
234 | |
229 return true; | 235 return true; |
230 end | 236 end |
231 | 237 |
232 local function list_append(username, host, datastore, data) | 238 local function list_append(username, host, datastore, data) |
233 if not data then return; end | 239 if not data then return; end |