comparison mod_storage_xmlarchive/mod_storage_xmlarchive.lua @ 2676:1b081c8fc1d9

mod_storage_xmlarchive: Attempt to clean up orphaned files despite util.datamanager or internal storage having deleted the date index file (fixes #725)
author Kim Alvefur <zash@zash.se>
date Mon, 10 Apr 2017 21:09:44 +0200
parents 101a2a0b8b33
children e5ce64aee4ac
comparison
equal deleted inserted replaced
2675:101a2a0b8b33 2676:1b081c8fc1d9
277 if typ ~= "archive" then return nil, "unsupported-store"; end 277 if typ ~= "archive" then return nil, "unsupported-store"; end
278 return setmetatable({ store = store }, archive_mt); 278 return setmetatable({ store = store }, archive_mt);
279 end 279 end
280 280
281 function provider:purge(username) 281 function provider:purge(username)
282 for store in dm.stores(username, module.host) do 282 local encoded_username = dm.path_encode((username or "@") .. "@");
283 local dates = dm.list_load(username, module.host, store) or empty; 283 local basepath = prosody.paths.data .. "/" .. dm.path_encode(module.host);
284 if dates[1] and type(dates[1]) == "string" and dates[1]:match("^%d%d%d%d%-%d%d%-%d%d$") then 284 for store in lfs.dir(basepath) do
285 module:log("info", "Store %s looks like an archive store, emptying it...", store); 285 store = basepath .. "/" .. dm.path_encode(store);
286 provider:open(store, "archive"):delete(username); 286 if lfs.attributes(store, "mode") == "directory" then
287 end 287 for file in lfs.dir(store) do
288 end 288 if file:sub(1, #encoded_username) == encoded_username then
289 return true; 289 if file:sub(-4) == ".xml" or file:sub(-5) == ".list" then
290 os.remove(store .. "/" .. file);
291 end
292 end
293 end
294 return true;
295 end
296 end
290 end 297 end
291 298
292 module:provides("storage", provider); 299 module:provides("storage", provider);