mod_storage_muc_log/mod_storage_muc_log.lua
changeset 2361 093b70378fa5
parent 2360 49a01b78b45f
child 2824 f3a09a559201
equal deleted inserted replaced
2360:49a01b78b45f 2361:093b70378fa5
    65 		return ok, err;
    65 		return ok, err;
    66 	end
    66 	end
    67 	return today .. "_" .. #data;
    67 	return today .. "_" .. #data;
    68 end
    68 end
    69 
    69 
    70 function driver:find(node, query)
    70 function driver:dates(node)
    71 	local path = datamanager.getpath(node, host, datastore):match("(.*)/");
    71 	local path = datamanager.getpath(node, host, datastore):match("(.*)/");
    72 
    72 
    73 	local ok, iter, state, var = pcall(lfs.dir, path);
    73 	local ok, iter, state, var = pcall(lfs.dir, path);
    74 	if not ok then
    74 	if not ok then
    75 		module:log("warn", iter);
    75 		module:log("warn", iter);
    82 			dates[i], i = dir, i+1;
    82 			dates[i], i = dir, i+1;
    83 		end
    83 		end
    84 	end
    84 	end
    85 	if dates[1] == nil then return noop, 0; end
    85 	if dates[1] == nil then return noop, 0; end
    86 	table.sort(dates);
    86 	table.sort(dates);
       
    87 	return dates;
       
    88 end
       
    89 
       
    90 function driver:find(node, query)
       
    91 	local dates, err = self:dates(node);
       
    92 	if not dates then return dates, err; end
    87 
    93 
    88 	return coroutine.wrap(function ()
    94 	return coroutine.wrap(function ()
    89 		local start_date = query and query.start and os_date(datef, query.start) or dates[1];
    95 		local start_date = query and query.start and os_date(datef, query.start) or dates[1];
    90 		local end_date = query and query["end"] and os_date(datef, query["end"]) or dates[#dates];
    96 		local end_date = query and query["end"] and os_date(datef, query["end"]) or dates[#dates];
    91 		local start_time = query and query.start and os_date(timef, query.start) or dates[1];
    97 		local start_time = query and query.start and os_date(timef, query.start) or dates[1];