# HG changeset patch
# User Waqas Hussain <waqas20@gmail.com>
# Date 1343766994 -18000
# Node ID acfaf771f10e7c6aca4e7f19e870ae55f4f35623
# Parent  7a1eb302c562d170d19f15ae6062f1964889b0ae
util.datamanager: Don't use os.rename on non-POSIX. It doesn't overwrite exisitng files on Windows.

diff -r 7a1eb302c562 -r acfaf771f10e util/datamanager.lua
--- a/util/datamanager.lua	Wed Aug 01 01:36:30 2012 +0500
+++ b/util/datamanager.lua	Wed Aug 01 01:36:34 2012 +0500
@@ -171,6 +171,18 @@
 	return nil, msg;
 end
 
+if prosody.platform ~= "posix" then
+	-- os.rename does not overwrite existing files on Windows
+	-- TODO We could use Transactional NTFS on Vista and above
+	function atomic_store(filename, data)
+		local f, err = io_open(filename, "w");
+		if not f then return f, err; end
+		local ok, msg = f:write(data);
+		if not ok then f:close(); return ok, msg; end
+		return f:close();
+	end
+end
+
 function store(username, host, datastore, data)
 	if not data then
 		data = {};