瀏覽代碼

cmSystemTools: Improve RenameFile on Windows with MOVEFILE_WRITE_THROUGH

Add this flag to tell `MoveFileExW` to flush the rename to disk before
returning.

Issue: #19580
Ron W Moore 5 年之前
父節點
當前提交
d78c22aa64
共有 1 個文件被更改,包括 3 次插入1 次删除
  1. 3 1
      Source/cmSystemTools.cxx

+ 3 - 1
Source/cmSystemTools.cxx

@@ -885,8 +885,10 @@ void cmSystemTools::InitializeLibUV()
 namespace {
 bool cmMoveFile(std::wstring const& oldname, std::wstring const& newname)
 {
+  // Use MOVEFILE_REPLACE_EXISTING to replace an existing destination file.
+  // Use MOVEFILE_WRITE_THROUGH to flush the change to disk before returning.
   return MoveFileExW(oldname.c_str(), newname.c_str(),
-                     MOVEFILE_REPLACE_EXISTING);
+                     MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH);
 }
 }
 #endif