aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2013-04-07 20:28:12 +0100
committerMatthew Wild <mwild1@gmail.com>2013-04-07 20:28:12 +0100
commitaae8df412a2bae509d24b4af42f845003f6b9935 (patch)
tree4c41585b13e2062d4f79c24949a89faa20926f60 /util
parent98d807f5b6963c688656cc598bca6ea396e2029f (diff)
downloadprosody-aae8df412a2bae509d24b4af42f845003f6b9935.tar.gz
prosody-aae8df412a2bae509d24b4af42f845003f6b9935.zip
util.datamanager: Clear the cache of created directories on storage failure, and retry
Diffstat (limited to 'util')
-rw-r--r--util/datamanager.lua30
1 files changed, 19 insertions, 11 deletions
diff --git a/util/datamanager.lua b/util/datamanager.lua
index 9f29458c..4a4d62b3 100644
--- a/util/datamanager.lua
+++ b/util/datamanager.lua
@@ -187,17 +187,25 @@ function store(username, host, datastore, data)
-- 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