Changeset

3086:931acb1188b1

util.datamanager: When failing to load a file, and the file exists, return nil, error.
author Waqas Hussain <waqas20@gmail.com>
date Sat, 22 May 2010 05:49:21 +0500
parents 3085:cf01b0725272
children 3087:9b31e36528e0
files util/datamanager.lua
diffstat 1 files changed, 12 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/util/datamanager.lua	Sat May 22 03:54:50 2010 +0500
+++ b/util/datamanager.lua	Sat May 22 05:49:21 2010 +0500
@@ -21,12 +21,13 @@
 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 @@
 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