util/datamanager.lua
changeset 11373 87105a9a11df
parent 11292 5fd1f1b544a0
child 12391 05c250fa335a
equal deleted inserted replaced
11372:0bc3acf37428 11373: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