Comparison

util/datamanager.lua @ 5066:4be7093edde9

util.datamanager: Try to open in read+write mode, then retry with write mode if that fails (usually because it doesn't exist)
author Kim Alvefur <zash@zash.se>
date Tue, 31 Jul 2012 23:34:11 +0200
parent 5057:1e44678b5de2
child 5069:7b298f8bcbcb
comparison
equal deleted inserted replaced
5057:1e44678b5de2 5066:4be7093edde9
199 199
200 function list_append(username, host, datastore, data) 200 function list_append(username, host, datastore, data)
201 if not data then return; end 201 if not data then return; end
202 if callback(username, host, datastore) == false then return true; end 202 if callback(username, host, datastore) == false then return true; end
203 -- save the datastore 203 -- save the datastore
204 local f, msg = io_open(getpath(username, host, datastore, "list", true), "a"); 204 local f, msg = io_open(getpath(username, host, datastore, "list", true), "r+");
205 if not f then
206 f, msg = io_open(getpath(username, host, datastore, "list", true), "w");
207 end
205 if not f then 208 if not f then
206 log("error", "Unable to write to %s storage ('%s') for user: %s@%s", datastore, msg, username or "nil", host or "nil"); 209 log("error", "Unable to write to %s storage ('%s') for user: %s@%s", datastore, msg, username or "nil", host or "nil");
207 return; 210 return;
208 end 211 end
209 local data = "item(" .. serialize(data) .. ");\n"; 212 local data = "item(" .. serialize(data) .. ");\n";