aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorWaqas Hussain <waqas20@gmail.com>2010-05-22 05:49:21 +0500
committerWaqas Hussain <waqas20@gmail.com>2010-05-22 05:49:21 +0500
commit4499df4f45b9101ccd9078099f9a224b82822cb0 (patch)
tree59fd0973b3cdcc9deeb2bfebe8bc28c5a868ef8a /util
parentd2f33e44a085ee597cfece627c2e7c540ef74af0 (diff)
downloadprosody-4499df4f45b9101ccd9078099f9a224b82822cb0.tar.gz
prosody-4499df4f45b9101ccd9078099f9a224b82822cb0.zip
util.datamanager: When failing to load a file, and the file exists, return nil, error.
Diffstat (limited to 'util')
-rw-r--r--util/datamanager.lua16
1 files changed, 12 insertions, 4 deletions
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