Software /
code /
prosody
Changeset
7202:5bf0ff3882aa
util.datamanager: Explicit handling of each error condition (see #632)
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 27 Feb 2016 15:29:56 +0100 |
parents | 7201:7a8cffafeff0 |
children | 7203:be8b88ad35a3 |
files | util/datamanager.lua |
diffstat | 1 files changed, 16 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/util/datamanager.lua Thu Feb 25 22:37:41 2016 +0100 +++ b/util/datamanager.lua Sat Feb 27 15:29:56 2016 +0100 @@ -144,24 +144,26 @@ 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