From 7e71294f67e62e081271a2c384605bd7a4397429 Mon Sep 17 00:00:00 2001 From: Marco Cirillo Date: Sun, 7 Apr 2013 16:56:49 +0000 Subject: util.datamanager: expose path decode and encode functions. --- util/datamanager.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'util') diff --git a/util/datamanager.lua b/util/datamanager.lua index 383e738f..9f29458c 100644 --- a/util/datamanager.lua +++ b/util/datamanager.lua @@ -354,4 +354,6 @@ function purge(username, host) return #errs == 0, t_concat(errs, ", "); end +_M.path_decode = decode; +_M.path_encode = encode; return _M; -- cgit v1.2.3 From 5c21c86aab734465ac029051a7f21fc1e3291a72 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 7 Apr 2013 20:28:12 +0100 Subject: util.datamanager: Clear the cache of created directories on storage failure, and retry --- util/datamanager.lua | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'util') 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 -- cgit v1.2.3