Software /
code /
prosody
Comparison
util/datamanager.lua @ 5441:6a5c622cc6d4
util.datamanager: Clear the cache of created directories on storage failure, and retry
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 07 Apr 2013 20:28:12 +0100 |
parent | 5440:a943e5cbf083 |
child | 6575:bdaadf70a48f |
comparison
equal
deleted
inserted
replaced
5440:a943e5cbf083 | 5441:6a5c622cc6d4 |
---|---|
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 |