Changeset

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 2675:101a2a0b8b33
children 2677:6daaa1ad2559
files mod_storage_xmlarchive/mod_storage_xmlarchive.lua
diffstat 1 files changed, 13 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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);