Diff

mod_storage_xmlarchive/mod_storage_xmlarchive.lua @ 2702:caabb980d1d8

Merge commit
author tmolitor <thilo@eightysoft.de>
date Mon, 24 Apr 2017 20:57:23 +0200
parent 2676:1b081c8fc1d9
child 2813:e5ce64aee4ac
line wrap: on
line diff
--- a/mod_storage_xmlarchive/mod_storage_xmlarchive.lua	Mon Apr 24 20:56:56 2017 +0200
+++ b/mod_storage_xmlarchive/mod_storage_xmlarchive.lua	Mon Apr 24 20:57:23 2017 +0200
@@ -91,7 +91,7 @@
 	local stream_session = { notopen = true };
 	local stream_callbacks = { handlestanza = cb, stream_ns = "jabber:client", default_ns = "jabber:client" };
 	local stream = new_stream(stream_session, stream_callbacks);
-	local dates = self:dates() or empty;
+	local dates = self:dates(username) or empty;
 	local function reset_stream()
 		stream:reset();
 		stream_session.notopen = true;
@@ -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);