Comparison

util/datamanager.lua @ 5032:c40ea227f8af

util.datamanager: Add function for listing stores
author Kim Alvefur <zash@zash.se>
date Sat, 28 Jul 2012 21:22:42 +0200
parent 5024:d25e1b9332cc
child 5038:242c62ff8e77
comparison
equal deleted inserted replaced
5030:9962fc19f9e9 5032:c40ea227f8af
224 return nil, "Error reading storage"; 224 return nil, "Error reading storage";
225 end 225 end
226 return items; 226 return items;
227 end 227 end
228 228
229 function list_stores(username, host)
230 if not host then
231 return nil, "bad argument #2 to 'list_stores' (string expected, got nothing)";
232 end
233 local list = {};
234 local host_dir = format("%s/%s/", data_path, encode(host));
235 for node in lfs.dir(host_dir) do
236 if not node:match"^%." then -- dots should be encoded, this is probably . or ..
237 local store = decode(node);
238 local path = host_dir..node;
239 if username == true then
240 if lfs.attributes(path, "mode") == "directory" then
241 list[#list+1] = store;
242 end
243 elseif username then
244 if lfs.attributes(getpath(username, host, store), "mode")
245 or lfs.attributes(getpath(username, host, store, "list"), "mode") then
246 list[#list+1] = store;
247 end
248 elseif lfs.attributes(path, "mode") == "file" then
249 list[#list+1] = store:gsub("%.[dalist]+$","");
250 end
251 end
252 end
253 return list;
254 end
255
229 return _M; 256 return _M;