diff options
author | Matthew Wild <mwild1@gmail.com> | 2012-07-28 20:59:03 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2012-07-28 20:59:03 +0100 |
commit | 8aafe03289bdc2e8697bf72d226c4325ffc8d51f (patch) | |
tree | 57f657bdb5f9107ab5d46cd8ea6e0f18e7a20b11 /util/datamanager.lua | |
parent | 655defbb532f079c1476511db9c47b141a1d9792 (diff) | |
parent | 5e57a36957ea2d717865eefa2155c5dc854f8b4d (diff) | |
download | prosody-8aafe03289bdc2e8697bf72d226c4325ffc8d51f.tar.gz prosody-8aafe03289bdc2e8697bf72d226c4325ffc8d51f.zip |
Merge with Zash
Diffstat (limited to 'util/datamanager.lua')
-rw-r--r-- | util/datamanager.lua | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/util/datamanager.lua b/util/datamanager.lua index 344d2eb1..23a2d74f 100644 --- a/util/datamanager.lua +++ b/util/datamanager.lua @@ -226,4 +226,45 @@ 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 + +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; |