util.datamanager: Add function for removing all data belonging to a user
authorKim Alvefur <zash@zash.se>
Sat, 28 Jul 2012 19:31:54 +0000 (21:31 +0200)
committerKim Alvefur <zash@zash.se>
Sat, 28 Jul 2012 19:31:54 +0000 (21:31 +0200)
util/datamanager.lua

index c29fb416cfaa9433321bee9db7d779a382c75e8e..23a2d74f187ef24b697107dc187ed9eae06c9ab8 100644 (file)
@@ -253,4 +253,18 @@ function list_stores(username, host)
        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;