Software /
code /
prosody
Comparison
util/datamanager.lua @ 11369:87105a9a11df
util.datamanager: Support iterating over any file extension
The 'typ' argument to all other functions is the actual file extension,
but not here for some reason.
May need this for iterating over the .bin files created by
mod_http_file_share in the future.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 07 Feb 2021 19:23:33 +0100 |
parent | 11288:5fd1f1b544a0 |
child | 12387:05c250fa335a |
comparison
equal
deleted
inserted
replaced
11368:0bc3acf37428 | 11369:87105a9a11df |
---|---|
318 keyval = "dat"; | 318 keyval = "dat"; |
319 list = "list"; | 319 list = "list"; |
320 } | 320 } |
321 | 321 |
322 local function users(host, store, typ) -- luacheck: ignore 431/store | 322 local function users(host, store, typ) -- luacheck: ignore 431/store |
323 typ = type_map[typ or "keyval"]; | 323 typ = "."..(type_map[typ or "keyval"] or typ); |
324 local store_dir = format("%s/%s/%s", data_path, encode(host), store_encode(store)); | 324 local store_dir = format("%s/%s/%s", data_path, encode(host), store_encode(store)); |
325 | 325 |
326 local mode, err = lfs.attributes(store_dir, "mode"); | 326 local mode, err = lfs.attributes(store_dir, "mode"); |
327 if not mode then | 327 if not mode then |
328 return function() log("debug", "%s", err or (store_dir .. " does not exist")) end | 328 return function() log("debug", "%s", err or (store_dir .. " does not exist")) end |
329 end | 329 end |
330 local next, state = lfs.dir(store_dir); -- luacheck: ignore 431/next 431/state | 330 local next, state = lfs.dir(store_dir); -- luacheck: ignore 431/next 431/state |
331 return function(state) -- luacheck: ignore 431/state | 331 return function(state) -- luacheck: ignore 431/state |
332 for node in next, state do | 332 for node in next, state do |
333 local file, ext = node:match("^(.*)%.([dalist]+)$"); | 333 if node:sub(-#typ, -1) == typ then |
334 if file and ext == typ then | 334 return decode(node:sub(1, -#typ-1)); |
335 return decode(file); | |
336 end | 335 end |
337 end | 336 end |
338 end, state; | 337 end, state; |
339 end | 338 end |
340 | 339 |