diff options
author | Waqas Hussain <waqas20@gmail.com> | 2009-03-30 03:22:34 +0500 |
---|---|---|
committer | Waqas Hussain <waqas20@gmail.com> | 2009-03-30 03:22:34 +0500 |
commit | 703044ae390898c17ed8268750b7e966dd789b38 (patch) | |
tree | b87bcd45ccf80a5ee8a1dc57fec606279b3a47f8 /util/datamanager.lua | |
parent | 985a40227efb833c3ff085dc0001f93ce2b9e751 (diff) | |
download | prosody-703044ae390898c17ed8268750b7e966dd789b38.tar.gz prosody-703044ae390898c17ed8268750b7e966dd789b38.zip |
Added: datamanager: Allow a callback to be installed which selectively prevents disk writes
Diffstat (limited to 'util/datamanager.lua')
-rw-r--r-- | util/datamanager.lua | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/util/datamanager.lua b/util/datamanager.lua index f67c8864..614f0c80 100644 --- a/util/datamanager.lua +++ b/util/datamanager.lua @@ -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 |