From 4499df4f45b9101ccd9078099f9a224b82822cb0 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Sat, 22 May 2010 05:49:21 +0500 Subject: util.datamanager: When failing to load a file, and the file exists, return nil, error. --- util/datamanager.lua | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'util/datamanager.lua') diff --git a/util/datamanager.lua b/util/datamanager.lua index 01c7aab2..9d96e5b3 100644 --- a/util/datamanager.lua +++ b/util/datamanager.lua @@ -21,12 +21,13 @@ local next = next; local t_insert = table.insert; local append = require "util.serialization".append; local path_separator = "/"; if os.getenv("WINDIR") then path_separator = "\\" end +local lfs = require "lfs"; local raw_mkdir; if prosody.platform == "posix" then raw_mkdir = require "util.pposix".mkdir; -- Doesn't trample on umask else - raw_mkdir = require "lfs".mkdir; + raw_mkdir = lfs.mkdir; end module "datamanager" @@ -111,14 +112,21 @@ end function load(username, host, datastore) local data, ret = loadfile(getpath(username, host, datastore)); if not data then - log("debug", "Failed to load "..datastore.." storage ('"..ret.."') for user: "..(username or "nil").."@"..(host or "nil")); - return nil; + local mode = lfs.attributes(getpath(username, host, datastore), "mode"); + if not mode then + log("debug", "Failed to load "..datastore.." storage ('"..ret.."') for user: "..(username or "nil").."@"..(host or "nil")); + return nil; + else -- file exists, but can't be read + -- TODO more detailed error checking and logging? + log("error", "Failed to load "..datastore.." storage ('"..ret.."') for user: "..(username or "nil").."@"..(host or "nil")); + return nil, "Error reading storage"; + end end setfenv(data, {}); local success, ret = pcall(data); if not success then log("error", "Unable to load "..datastore.." storage ('"..ret.."') for user: "..(username or "nil").."@"..(host or "nil")); - return nil; + return nil, "Error reading storage"; end return ret; end -- cgit v1.2.3 From 42f63b21d79733a2198952245df0673434bd31d2 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Sun, 23 May 2010 23:55:01 +0500 Subject: util.datamanager: Return an error string when failing to save. --- util/datamanager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'util/datamanager.lua') diff --git a/util/datamanager.lua b/util/datamanager.lua index 9d96e5b3..57cd2594 100644 --- a/util/datamanager.lua +++ b/util/datamanager.lua @@ -145,7 +145,7 @@ function store(username, host, datastore, data) local f, msg = io_open(getpath(username, host, datastore, nil, true), "w+"); if not f then log("error", "Unable to write to "..datastore.." storage ('"..msg.."') for user: "..(username or "nil").."@"..(host or "nil")); - return; + return nil, "Error saving to storage"; end f:write("return "); append(f, data); -- cgit v1.2.3