mod_storage_xep0227: Open file for writing even if removing so os.remove has a file to delete
authorKim Alvefur <zash@zash.se>
Fri, 15 May 2015 15:25:37 +0200
changeset 6702 ccdd0b615106
parent 6701 95a8aeca1fc9
child 6703 0103dc8fa179
mod_storage_xep0227: Open file for writing even if removing so os.remove has a file to delete
plugins/mod_storage_xep0227.lua
--- a/plugins/mod_storage_xep0227.lua	Fri May 15 15:17:27 2015 +0200
+++ b/plugins/mod_storage_xep0227.lua	Fri May 15 15:25:37 2015 +0200
@@ -23,14 +23,15 @@
 local function setXml(user, host, xml)
 	local jid = user.."@"..host;
 	local path = paths.join(prosody.paths.data, jid..".xml");
+	local f = io_open(path, "w");
+	if not f then return; end
 	if xml then
-		local f = io_open(path, "w");
-		if not f then return; end
 		local s = tostring(xml);
 		f:write(s);
 		f:close();
 		return true;
 	else
+		f:close();
 		return os_remove(path);
 	end
 end