From 8b514a0692d0deb6d1c0b9ddcb94f794c4d25b6e Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 28 Jul 2012 21:22:42 +0200 Subject: util.datamanager: Add function for listing stores --- util/datamanager.lua | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'util/datamanager.lua') diff --git a/util/datamanager.lua b/util/datamanager.lua index 344d2eb1..c29fb416 100644 --- a/util/datamanager.lua +++ b/util/datamanager.lua @@ -226,4 +226,31 @@ function list_load(username, host, datastore) return items; end +function list_stores(username, host) + if not host then + return nil, "bad argument #2 to 'list_stores' (string expected, got nothing)"; + end + local list = {}; + local host_dir = format("%s/%s/", data_path, encode(host)); + for node in lfs.dir(host_dir) do + if not node:match"^%." then -- dots should be encoded, this is probably . or .. + local store = decode(node); + local path = host_dir..node; + if username == true then + if lfs.attributes(path, "mode") == "directory" then + list[#list+1] = store; + end + elseif username then + if lfs.attributes(getpath(username, host, store), "mode") + or lfs.attributes(getpath(username, host, store, "list"), "mode") then + list[#list+1] = store; + end + elseif lfs.attributes(path, "mode") == "file" then + list[#list+1] = store:gsub("%.[dalist]+$",""); + end + end + end + return list; +end + return _M; -- cgit v1.2.3 From bf14c1db606376599a6c6c75d234a640ea5519a6 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 28 Jul 2012 21:31:54 +0200 Subject: util.datamanager: Add function for removing all data belonging to a user --- util/datamanager.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'util/datamanager.lua') diff --git a/util/datamanager.lua b/util/datamanager.lua index c29fb416..23a2d74f 100644 --- a/util/datamanager.lua +++ b/util/datamanager.lua @@ -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; -- cgit v1.2.3