Changeset

5038:242c62ff8e77

util.datamanager: Add function for removing all data belonging to a user
author Kim Alvefur <zash@zash.se>
date Sat, 28 Jul 2012 21:31:54 +0200
parents 5037:c34fdcae6d29
children 5039:656ce68c4781
files util/datamanager.lua
diffstat 1 files changed, 14 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/util/datamanager.lua	Sat Jul 28 21:30:54 2012 +0200
+++ b/util/datamanager.lua	Sat Jul 28 21:31:54 2012 +0200
@@ -253,4 +253,18 @@
 	return list;
 end
 
+function purge(username, host)
+	local host_dir = format("%s/%s/", data_path, encode(host));
+	local deleted = 0;
+	for file in lfs.dir(host_dir) do
+		if lfs.attributes(host_dir..file, "mode") == "directory" then
+			local store = decode(file);
+			deleted = deleted + (os_remove(getpath(username, host, store)) and 1 or 0);
+			deleted = deleted + (os_remove(getpath(username, host, store, "list")) and 1 or 0);
+			-- We this will generate loads of "No such file or directory", but do we care?
+		end
+	end
+	return deleted > 0, deleted;
+end
+
 return _M;