Changeset

117:8e5c5e6a3240

Fixed: datamanager.store and datamanager.load could crash when username or host arguments were nil. (useful for server specific and global data).
author Waqas Hussain <waqas20@gmail.com>
date Thu, 23 Oct 2008 02:49:43 +0500
parents 116:72e698cdabd7
children 118:76ac96c53ee5
files util/datamanager.lua
diffstat 1 files changed, 12 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/util/datamanager.lua	Thu Oct 23 02:19:26 2008 +0500
+++ b/util/datamanager.lua	Thu Oct 23 02:49:43 2008 +0500
@@ -68,16 +68,25 @@
 
 function load(username, host, datastore)
 	local data, ret = loadfile(getpath(username, host, datastore));
-	if not data then log("warn", "Failed to load "..datastore.." storage ('"..ret.."') for user: "..username.."@"..host); return nil; end
+	if not data then
+		log("warn", "Failed to load "..datastore.." storage ('"..ret.."') for user: "..(username or nil).."@"..(host or nil));
+		return nil;
+	end
 	setfenv(data, {});
 	local success, ret = pcall(data);
-	if not success then log("error", "Unable to load "..datastore.." storage ('"..ret.."') for user: "..username.."@"..host); return nil; end
+	if not success then
+		log("error", "Unable to load "..datastore.." storage ('"..ret.."') for user: "..(username or nil).."@"..(host or nil));
+		return nil;
+	end
 	return ret;
 end
 
 function store(username, host, datastore, data)
 	local f, msg = io_open(getpath(username, host, datastore), "w+");
-	if not f then log("error", "Unable to write to "..datastore.." storage ('"..msg.."') for user: "..username.."@"..host); return nil; end
+	if not f then
+		log("error", "Unable to write to "..datastore.." storage ('"..msg.."') for user: "..(username or nil).."@"..(host or nil));
+		return nil;
+	end
 	f:write("return ");
 	simplesave(f, data);
 	f:close();