# HG changeset patch # User Marco Cirillo # Date 1365375136 -7200 # Node ID 08628703456a09b94321558163baf5ee8b3858ab # Parent 224e3745c1b39127f6f943fc7822001f8f9482e0 mod_muc_log_http: do some more cleanup of the code. diff -r 224e3745c1b3 -r 08628703456a mod_muc_log_http/muc_log_http/mod_muc_log_http.lua --- 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;