aboutsummaryrefslogtreecommitdiffstats
path: root/util/datamanager.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2016-02-27 15:29:56 +0100
committerKim Alvefur <zash@zash.se>2016-02-27 15:29:56 +0100
commitafe389d87040e0f37012e4bebe3340013e5ed5a7 (patch)
tree0e7da5c8c90ea2d935f49e725c17fc1ceedd9b9c /util/datamanager.lua
parentd17785e91f5a14942de3257207f3f2d058162467 (diff)
downloadprosody-afe389d87040e0f37012e4bebe3340013e5ed5a7.tar.gz
prosody-afe389d87040e0f37012e4bebe3340013e5ed5a7.zip
util.datamanager: Explicit handling of each error condition (see #632)
Diffstat (limited to 'util/datamanager.lua')
-rw-r--r--util/datamanager.lua30
1 files changed, 16 insertions, 14 deletions
diff --git a/util/datamanager.lua b/util/datamanager.lua
index 07b2fe4a..dc98bd13 100644
--- a/util/datamanager.lua
+++ b/util/datamanager.lua
@@ -144,24 +144,26 @@ end
local function atomic_store(filename, data)
local scratch = filename.."~";
local f, ok, msg;
- repeat
- f, msg = io_open(scratch, "w");
- if not f then break end
- ok, msg = f:write(data);
- if not ok then break end
+ f, msg = io_open(scratch, "w");
+ if not f then
+ return nil, msg;
+ end
- ok, msg = f:close();
- f = nil; -- no longer valid
- if not ok then break end
+ ok, msg = f:write(data);
+ if not ok then
+ f:close();
+ os_remove(scratch);
+ return nil, msg;
+ end
- return os_rename(scratch, filename);
- until false;
+ ok, msg = f:close();
+ if not ok then
+ os_remove(scratch);
+ return nil, msg;
+ end
- -- Cleanup
- if f then f:close(); end
- os_remove(scratch);
- return nil, msg;
+ return os_rename(scratch, filename);
end
if prosody and prosody.platform ~= "posix" then