Comparison

util/datamanager.lua @ 7207:14ea924a036d

Merge 0.10->trunk
author Kim Alvefur <zash@zash.se>
date Sun, 28 Feb 2016 15:06:56 +0100
parent 7202:5bf0ff3882aa
child 7432:92f721226753
comparison
equal deleted inserted replaced
7195:39b7ea9141c0 7207:14ea924a036d
142 end 142 end
143 143
144 local function atomic_store(filename, data) 144 local function atomic_store(filename, data)
145 local scratch = filename.."~"; 145 local scratch = filename.."~";
146 local f, ok, msg; 146 local f, ok, msg;
147 repeat 147
148 f, msg = io_open(scratch, "w"); 148 f, msg = io_open(scratch, "w");
149 if not f then break end 149 if not f then
150 150 return nil, msg;
151 ok, msg = f:write(data); 151 end
152 if not ok then break end 152
153 153 ok, msg = f:write(data);
154 ok, msg = f:close(); 154 if not ok then
155 if not ok then break end 155 f:close();
156 156 os_remove(scratch);
157 return os_rename(scratch, filename); 157 return nil, msg;
158 until false; 158 end
159 159
160 -- Cleanup 160 ok, msg = f:close();
161 if f then f:close(); end 161 if not ok then
162 os_remove(scratch); 162 os_remove(scratch);
163 return nil, msg; 163 return nil, msg;
164 end
165
166 return os_rename(scratch, filename);
164 end 167 end
165 168
166 if prosody and prosody.platform ~= "posix" then 169 if prosody and prosody.platform ~= "posix" then
167 -- os.rename does not overwrite existing files on Windows 170 -- os.rename does not overwrite existing files on Windows
168 -- TODO We could use Transactional NTFS on Vista and above 171 -- TODO We could use Transactional NTFS on Vista and above