diff options
author | Waqas Hussain <waqas20@gmail.com> | 2008-11-03 07:50:09 +0500 |
---|---|---|
committer | Waqas Hussain <waqas20@gmail.com> | 2008-11-03 07:50:09 +0500 |
commit | eb599a8379ab319218a674b299e455510e2da055 (patch) | |
tree | f173dfcce73c1db36f65cfb721e62cbe9f085b53 /util | |
parent | db114e8e3f6e97ac142b8836b1a4e5db301e6d50 (diff) | |
download | prosody-eb599a8379ab319218a674b299e455510e2da055.tar.gz prosody-eb599a8379ab319218a674b299e455510e2da055.zip |
Datamanager now deletes files with no data
Diffstat (limited to 'util')
-rw-r--r-- | util/datamanager.lua | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/util/datamanager.lua b/util/datamanager.lua index e5a74acd..aad370d1 100644 --- a/util/datamanager.lua +++ b/util/datamanager.lua @@ -5,8 +5,10 @@ local char = string.char; local loadfile, setfenv, pcall = loadfile, setfenv, pcall; local log = log; local io_open = io.open; +local os_remove = os.remove; local tostring = tostring; local error = error; +local next = next; local indent = function(f, i) for n = 1, i do @@ -93,14 +95,23 @@ function load(username, host, datastore) end function store(username, host, datastore, data) + if not data then + data = {}; + end + -- save the datastore 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 or "nil").."@"..(host or "nil")); - return nil; + return; end f:write("return "); simplesave(f, data, 1); f:close(); + if not next(data) then -- try to delete empty datastore + os_remove(getpath(username, host, datastore)); + end + -- we write data even when we are deleting because lua doesn't have a + -- platform independent way of checking for non-exisitng files return true; end |