diff options
author | Kim Alvefur <zash@zash.se> | 2012-07-28 21:22:42 +0200 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2012-07-28 21:22:42 +0200 |
commit | 88784b42758c53ae76fa0eb2c58cbc2586f7d060 (patch) | |
tree | 8a9ac44c07f390c13914f6e1867faeabab755a13 | |
parent | 17174eb3c57ee776dda12fa59789c28c349cfb19 (diff) | |
download | prosody-88784b42758c53ae76fa0eb2c58cbc2586f7d060.tar.gz prosody-88784b42758c53ae76fa0eb2c58cbc2586f7d060.zip |
util.datamanager: Add function for listing stores
-rw-r--r-- | util/datamanager.lua | 27 |
1 files changed, 27 insertions, 0 deletions
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; |