util.datamanager: Don't use os.rename on non-POSIX. It doesn't overwrite exisitng...
authorWaqas Hussain <waqas20@gmail.com>
Tue, 31 Jul 2012 20:36:34 +0000 (01:36 +0500)
committerWaqas Hussain <waqas20@gmail.com>
Tue, 31 Jul 2012 20:36:34 +0000 (01:36 +0500)
util/datamanager.lua

index 79be07b06c0ded287862a1d0c5603ff7f397358b..ecf90bab6e07245fae041894e20e5fd63127fb4b 100644 (file)
@@ -171,6 +171,18 @@ local function atomic_store(filename, data)
        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 = {};