aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2012-09-19 12:14:08 +0100
committerMatthew Wild <mwild1@gmail.com>2012-09-19 12:14:08 +0100
commitfc11c75968dab816534939aafb2378dcd052c5e5 (patch)
treecf7a08a965f0bb9816285dcc830a140b62fc0ab1 /util
parent5f27e2a04037afdb5da8ef53b88ffa7b25014e32 (diff)
parentec41d90e0f1dd90bf7908acbf5ab25301dec9519 (diff)
downloadprosody-fc11c75968dab816534939aafb2378dcd052c5e5.tar.gz
prosody-fc11c75968dab816534939aafb2378dcd052c5e5.zip
Merge 0.9->trunk
Diffstat (limited to 'util')
-rw-r--r--util/datamanager.lua52
1 files changed, 31 insertions, 21 deletions
diff --git a/util/datamanager.lua b/util/datamanager.lua
index e6ad86db..9207f555 100644
--- a/util/datamanager.lua
+++ b/util/datamanager.lua
@@ -277,31 +277,41 @@ 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)";
+local type_map = {
+ keyval = "dat";
+ list = "list";
+}
+
+function stores(username, host, typ)
+ typ = type_map[typ or "keyval"];
+ local store_dir = format("%s/%s/", data_path, encode(host));
+
+ local mode, err = lfs.attributes(store_dir, "mode");
+ if not mode then
+ return function() log("debug", err or (store_dir .. " does not exist")) end
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;
+ local next, state = lfs.dir(store_dir);
+ return function(state)
+ for node in next, state do
+ if not node:match"^%." then
+ if username == true then
+ if lfs.attributes(store_dir..node, "mode") == "directory" then
+ return decode(node);
+ end
+ elseif username then
+ local store = decode(node)
+ if lfs.attributes(getpath(username, host, store, typ), "mode") then
+ return store;
+ end
+ elseif lfs.attributes(node, "mode") == "file" then
+ local file, ext = node:match("^(.*)%.([dalist]+)$");
+ if ext == typ then
+ return decode(file)
+ end
end
- elseif lfs.attributes(path, "mode") == "file" then
- list[#list+1] = store:gsub("%.[dalist]+$","");
end
end
- end
- return list;
+ end, state;
end
local function do_remove(path)