Software /
code /
prosody
Comparison
util/datamanager.lua @ 5153:688aeac0012a
mod_storage_internal, datamanager: Add support for iterating over users with data in a store
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 21 Sep 2012 17:23:08 +0200 |
parent | 5130:051d352ed03c |
child | 5243:07e8256efcda |
comparison
equal
deleted
inserted
replaced
5152:fee5f8d4ec74 | 5153:688aeac0012a |
---|---|
279 | 279 |
280 local type_map = { | 280 local type_map = { |
281 keyval = "dat"; | 281 keyval = "dat"; |
282 list = "list"; | 282 list = "list"; |
283 } | 283 } |
284 | |
285 function users(host, store, typ) | |
286 typ = type_map[typ or "keyval"]; | |
287 local store_dir = format("%s/%s/%s", data_path, encode(host), encode(store)); | |
288 | |
289 local mode, err = lfs.attributes(store_dir, "mode"); | |
290 if not mode then | |
291 return function() log("debug", err or (store_dir .. " does not exist")) end | |
292 end | |
293 local next, state = lfs.dir(store_dir); | |
294 return function(state) | |
295 for node in next, state do | |
296 local file, ext = node:match("^(.*)%.([dalist]+)$"); | |
297 if file and ext == typ then | |
298 return decode(file); | |
299 end | |
300 end | |
301 end, state; | |
302 end | |
284 | 303 |
285 function stores(username, host, typ) | 304 function stores(username, host, typ) |
286 typ = type_map[typ or "keyval"]; | 305 typ = type_map[typ or "keyval"]; |
287 local store_dir = format("%s/%s/", data_path, encode(host)); | 306 local store_dir = format("%s/%s/", data_path, encode(host)); |
288 | 307 |