# HG changeset patch # User Kim Alvefur # Date 1491851384 -7200 # Node ID 1b081c8fc1d90819a08a5fbdaf817f0c8626463f # Parent 101a2a0b8b33420fc0e7e487d9d3aef365342fda mod_storage_xmlarchive: Attempt to clean up orphaned files despite util.datamanager or internal storage having deleted the date index file (fixes #725) diff -r 101a2a0b8b33 -r 1b081c8fc1d9 mod_storage_xmlarchive/mod_storage_xmlarchive.lua --- a/mod_storage_xmlarchive/mod_storage_xmlarchive.lua Mon Apr 10 08:59:13 2017 +0200 +++ b/mod_storage_xmlarchive/mod_storage_xmlarchive.lua Mon Apr 10 21:09:44 2017 +0200 @@ -279,14 +279,21 @@ end function provider:purge(username) - for store in dm.stores(username, module.host) do - local dates = dm.list_load(username, module.host, store) or empty; - if dates[1] and type(dates[1]) == "string" and dates[1]:match("^%d%d%d%d%-%d%d%-%d%d$") then - module:log("info", "Store %s looks like an archive store, emptying it...", store); - provider:open(store, "archive"):delete(username); + local encoded_username = dm.path_encode((username or "@") .. "@"); + local basepath = prosody.paths.data .. "/" .. dm.path_encode(module.host); + for store in lfs.dir(basepath) do + store = basepath .. "/" .. dm.path_encode(store); + if lfs.attributes(store, "mode") == "directory" then + for file in lfs.dir(store) do + if file:sub(1, #encoded_username) == encoded_username then + if file:sub(-4) == ".xml" or file:sub(-5) == ".list" then + os.remove(store .. "/" .. file); + end + end + end + return true; end end - return true; end module:provides("storage", provider);