changeset 975:08628703456a

mod_muc_log_http: do some more cleanup of the code.
author Marco Cirillo <maranda@lightwitch.org>
date Mon, 08 Apr 2013 00:52:16 +0200
parents 224e3745c1b3
children 0428009c1127
files mod_muc_log_http/muc_log_http/mod_muc_log_http.lua
diffstat 1 files changed, 8 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/mod_muc_log_http/muc_log_http/mod_muc_log_http.lua	Sun Apr 07 19:03:55 2013 +0200
+++ b/mod_muc_log_http/muc_log_http/mod_muc_log_http.lua	Mon Apr 08 00:52:16 2013 +0200
@@ -27,33 +27,14 @@
 local html = {};
 local theme;
 
--- encoding function
-local p_encode = datamanager.path_encode;
-
-local function checkDatastorePathExists(node, host, today, create)
-	create = create or false;
-	local path = data_getpath(node, host, datastore, "dat", true);
-	path = path:gsub("/[^/]*$", "");
+-- Helper Functions
 
-	-- check existance
-	local attributes, err = lfs.attributes(path);
-	if attributes == nil or attributes.mode ~= "directory" then
-		module:log("warn", "muc_log folder isn't a folder: %s", path);
-		return false;
-	end
+local p_encode = datamanager.path_encode;
+local function store_exists(node, host, today)
+	if lfs.attributes(data_getpath(node, host, datastore .. "/" .. today), "mode") then return true; else return false; end
+end
 
-	attributes, err = lfs.attributes(path .. "/" .. today);
-	if attributes == nil then
-		if create then
-			return lfs.mkdir(path .. "/" .. today);
-		else
-			return false;
-		end
-	elseif attributes.mode == "directory" then
-		return true;
-	end
-	return false;
-end
+-- Module Definitions
 
 local function htmlEscape(t)
 	if t then
@@ -465,7 +446,7 @@
 	local max_trys = 7;
 
 	module:log("debug", day);
-	while(not checkDatastorePathExists(node, host, day, false)) do
+	while(not store_exists(node, host, day)) do
 		max_trys = max_trys - 1;
 		if max_trys == 0 then
 			break;
@@ -522,7 +503,7 @@
 	local day = decrementDay(bare_day);
 	local max_trys = 7;
 	module:log("debug", day);
-	while(not checkDatastorePathExists(node, host, day, false)) do
+	while(not store_exists(node, host, day)) do
 		max_trys = max_trys - 1;
 		if max_trys == 0 then
 			break;