@@ -233,23 +233,21 @@ void file_rename(const std::string &old_path, const std::string &new_path)
233
233
MoveFileW (widen (old_path).c_str (), widen (new_path).c_str ());
234
234
235
235
if (MoveFile_result == 0 )
236
- throw system_exceptiont (" MoveFile failed" );
236
+ throw system_exceptiont (" MoveFileW failed" );
237
237
}
238
238
else
239
239
{
240
- // C++17 requires this to be atomic, which is delivered by
241
- // ReplaceFile(). MoveFile() or rename() do not guarantee this.
240
+ // C++17 requires this to be atomic.
241
+ // MoveFile, MoveFileEx () or rename() do not guarantee this.
242
242
// Any existing file at new_path is to be overwritten.
243
- auto ReplaceFile_result = ReplaceFileW (
244
- widen (new_path). c_str (), // note the ordering
243
+ // rename() does not do so on Windows.
244
+ auto MoveFileEx_result = MoveFileExW (
245
245
widen (old_path).c_str (),
246
- nullptr , // lpBackupFileName
247
- 0 , // dwReplaceFlags
248
- nullptr , // lpExclude
249
- nullptr ); // lpReserved
246
+ widen (new_path).c_str (),
247
+ MOVEFILE_REPLACE_EXISTING); // flags
250
248
251
- if (ReplaceFile_result == 0 )
252
- throw system_exceptiont (" ReplaceFile failed" );
249
+ if (MoveFileEx_result == 0 )
250
+ throw system_exceptiont (" MoveFileExW failed" );
253
251
}
254
252
#else
255
253
int rename_result = rename (old_path.c_str (), new_path.c_str ());
0 commit comments