Software /
code /
prosody
Changeset
5032:c40ea227f8af
util.datamanager: Add function for listing stores
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 28 Jul 2012 21:22:42 +0200 |
parents | 5030:9962fc19f9e9 |
children | 5033:c64b5081bfa8 |
files | util/datamanager.lua |
diffstat | 1 files changed, 27 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/util/datamanager.lua Sat Jul 28 01:28:14 2012 +0100 +++ b/util/datamanager.lua Sat Jul 28 21:22:42 2012 +0200 @@ -226,4 +226,31 @@ 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;