# HG changeset patch # User Kim Alvefur # Date 1456583396 -3600 # Node ID 5bf0ff3882aa4a6c231091592552766f848b31b2 # Parent 7a8cffafeff080278c0ddea6e6b2931b27e2648c util.datamanager: Explicit handling of each error condition (see #632) diff -r 7a8cffafeff0 -r 5bf0ff3882aa util/datamanager.lua --- 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