Added: datamanager: Allow a callback to be installed which selectively prevents disk writes

Mon, 30 Mar 2009 03:22:34 +0500

author
Waqas Hussain <waqas20@gmail.com>
date
Mon, 30 Mar 2009 03:22:34 +0500
changeset 932
1ed3e5fe165a
parent 931
4514ed5ee943
child 933
2a5352e0e10e

Added: datamanager: Allow a callback to be installed which selectively prevents disk writes

util/datamanager.lua file | annotate | diff | comparison | revisions
--- a/util/datamanager.lua	Mon Mar 30 03:06:01 2009 +0500
+++ b/util/datamanager.lua	Mon Mar 30 03:22:34 2009 +0500
@@ -50,6 +50,7 @@
 end
 
 local data_path = "data";
+local callback;
 
 ------- API -------------
 
@@ -57,6 +58,9 @@
 	log("info", "Setting data path to: %s", path);
 	data_path = path;
 end
+function set_callback(func)
+	callback = func;
+end
 
 function getpath(username, host, datastore, ext, create)
 	ext = ext or "dat";
@@ -93,6 +97,7 @@
 	if not data then
 		data = {};
 	end
+	if callback and callback(username, host, datastore) then return true; end
 	-- save the datastore
 	local f, msg = io_open(getpath(username, host, datastore, nil, true), "w+");
 	if not f then
@@ -113,6 +118,7 @@
 
 function list_append(username, host, datastore, data)
 	if not data then return; end
+	if callback and callback(username, host, datastore) then return true; end
 	-- save the datastore
 	local f, msg = io_open(getpath(username, host, datastore, "list", true), "a+");
 	if not f then
@@ -130,6 +136,7 @@
 	if not data then
 		data = {};
 	end
+	if callback and callback(username, host, datastore) then return true; end
 	-- save the datastore
 	local f, msg = io_open(getpath(username, host, datastore, "list", true), "w+");
 	if not f then

mercurial