Software /
code /
prosody
Diff
util/datamanager.lua @ 5441:6a5c622cc6d4
util.datamanager: Clear the cache of created directories on storage failure, and retry
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 07 Apr 2013 20:28:12 +0100 |
parent | 5440:a943e5cbf083 |
child | 6575:bdaadf70a48f |
line wrap: on
line diff
--- a/util/datamanager.lua Sun Apr 07 16:56:49 2013 +0000 +++ b/util/datamanager.lua Sun Apr 07 20:28:12 2013 +0100 @@ -187,17 +187,25 @@ -- save the datastore local d = "return " .. serialize(data) .. ";\n"; - local ok, msg = atomic_store(getpath(username, host, datastore, nil, true), d); - if not ok then - log("error", "Unable to write to %s storage ('%s') for user: %s@%s", datastore, msg, username or "nil", host or "nil"); - return nil, "Error saving to storage"; - end - if next(data) == nil then -- try to delete empty datastore - log("debug", "Removing empty %s datastore for user %s@%s", datastore, username or "nil", host or "nil"); - 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 + local mkdir_cache_cleared; + repeat + local ok, msg = atomic_store(getpath(username, host, datastore, nil, true), d); + if not ok then + if not mkdir_cache_cleared then -- We may need to recreate a removed directory + _mkdir = {}; + mkdir_cache_cleared = true; + else + log("error", "Unable to write to %s storage ('%s') for user: %s@%s", datastore, msg, username or "nil", host or "nil"); + return nil, "Error saving to storage"; + end + end + if next(data) == nil then -- try to delete empty datastore + log("debug", "Removing empty %s datastore for user %s@%s", datastore, username or "nil", host or "nil"); + 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 + until ok; return true; end