util.datamanager: When failing to load a list file, and the file exists, log an error, and return nil, error.

Fri, 10 Dec 2010 00:21:09 +0500

author
Waqas Hussain <waqas20@gmail.com>
date
Fri, 10 Dec 2010 00:21:09 +0500
changeset 3844
9cdc19ed3034
parent 3843
997f699323f6
child 3845
4860853fc97b

util.datamanager: When failing to load a list file, and the file exists, log an error, and return nil, error.

util/datamanager.lua file | annotate | diff | comparison | revisions
--- a/util/datamanager.lua	Fri Dec 10 00:07:28 2010 +0500
+++ b/util/datamanager.lua	Fri Dec 10 00:21:09 2010 +0500
@@ -204,8 +204,15 @@
 function list_load(username, host, datastore)
 	local data, ret = loadfile(getpath(username, host, datastore, "list"));
 	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, "list"), "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
 	local items = {};
 	setfenv(data, {item = function(i) t_insert(items, i); end});

mercurial