Added: datamanager: Allow a callback to be installed which selectively prevents disk...
authorWaqas Hussain <waqas20@gmail.com>
Sun, 29 Mar 2009 22:22:34 +0000 (03:22 +0500)
committerWaqas Hussain <waqas20@gmail.com>
Sun, 29 Mar 2009 22:22:34 +0000 (03:22 +0500)
util/datamanager.lua

index f67c886478456db206a2b4857870e520a1568fba..614f0c80c5b33d7d4c3e14c3d2fcc45b34d31f5c 100644 (file)
@@ -50,6 +50,7 @@ local function mkdir(path)
 end
 
 local data_path = "data";
+local callback;
 
 ------- API -------------
 
@@ -57,6 +58,9 @@ function set_data_path(path)
        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 @@ function store(username, host, datastore, data)
        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 @@ end
 
 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 @@ function list_store(username, host, datastore, data)
        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