Comparison

util/datamanager.lua @ 5442:e66973c81e89

Merge 0.9->trunk
author Matthew Wild <mwild1@gmail.com>
date Mon, 08 Apr 2013 12:08:34 +0100
parent 5441:6a5c622cc6d4
child 6575:bdaadf70a48f
comparison
equal deleted inserted replaced
5437:1994a4483b1c 5442:e66973c81e89
185 return true; -- Don't save this data at all 185 return true; -- Don't save this data at all
186 end 186 end
187 187
188 -- save the datastore 188 -- save the datastore
189 local d = "return " .. serialize(data) .. ";\n"; 189 local d = "return " .. serialize(data) .. ";\n";
190 local ok, msg = atomic_store(getpath(username, host, datastore, nil, true), d); 190 local mkdir_cache_cleared;
191 if not ok then 191 repeat
192 log("error", "Unable to write to %s storage ('%s') for user: %s@%s", datastore, msg, username or "nil", host or "nil"); 192 local ok, msg = atomic_store(getpath(username, host, datastore, nil, true), d);
193 return nil, "Error saving to storage"; 193 if not ok then
194 end 194 if not mkdir_cache_cleared then -- We may need to recreate a removed directory
195 if next(data) == nil then -- try to delete empty datastore 195 _mkdir = {};
196 log("debug", "Removing empty %s datastore for user %s@%s", datastore, username or "nil", host or "nil"); 196 mkdir_cache_cleared = true;
197 os_remove(getpath(username, host, datastore)); 197 else
198 end 198 log("error", "Unable to write to %s storage ('%s') for user: %s@%s", datastore, msg, username or "nil", host or "nil");
199 -- we write data even when we are deleting because lua doesn't have a 199 return nil, "Error saving to storage";
200 -- platform independent way of checking for non-exisitng files 200 end
201 end
202 if next(data) == nil then -- try to delete empty datastore
203 log("debug", "Removing empty %s datastore for user %s@%s", datastore, username or "nil", host or "nil");
204 os_remove(getpath(username, host, datastore));
205 end
206 -- we write data even when we are deleting because lua doesn't have a
207 -- platform independent way of checking for non-exisitng files
208 until ok;
201 return true; 209 return true;
202 end 210 end
203 211
204 function list_append(username, host, datastore, data) 212 function list_append(username, host, datastore, data)
205 if not data then return; end 213 if not data then return; end
352 end 360 end
353 end 361 end
354 return #errs == 0, t_concat(errs, ", "); 362 return #errs == 0, t_concat(errs, ", ");
355 end 363 end
356 364
365 _M.path_decode = decode;
366 _M.path_encode = encode;
357 return _M; 367 return _M;