1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 02:32:36 +01:00

Win32/File.cpp: Use ReplaceFile for hardlink overwrite

This commit is contained in:
Elad 2024-10-31 20:29:10 +02:00
parent b87c891ec4
commit 4206b022b6

View File

@ -2490,7 +2490,8 @@ bool fs::pending_file::commit(bool overwrite)
const auto ws1 = to_wchar(m_path); const auto ws1 = to_wchar(m_path);
const HANDLE file_handle = CreateFileW(ws1.get(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, nullptr); const HANDLE file_handle = !overwrite ? INVALID_HANDLE_VALUE
: CreateFileW(ws1.get(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, nullptr);
while (file_handle != INVALID_HANDLE_VALUE) while (file_handle != INVALID_HANDLE_VALUE)
{ {
@ -2551,6 +2552,12 @@ bool fs::pending_file::commit(bool overwrite)
CloseHandle(file_handle); CloseHandle(file_handle);
break; break;
} }
if (!hardlink_paths.empty())
{
// REPLACEFILE_WRITE_THROUGH is not supported
file.sync();
}
#endif #endif
file.close(); file.close();
@ -2558,14 +2565,19 @@ bool fs::pending_file::commit(bool overwrite)
#ifdef _WIN32 #ifdef _WIN32
const auto ws2 = to_wchar(m_dest); const auto ws2 = to_wchar(m_dest);
if (MoveFileExW(ws1.get(), ws2.get(), overwrite ? MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH : MOVEFILE_WRITE_THROUGH)) bool ok = false;
if (hardlink_paths.empty())
{ {
for (auto&& path : hardlink_paths) ok = MoveFileExW(ws1.get(), ws2.get(), overwrite ? MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH : MOVEFILE_WRITE_THROUGH);
}
else
{ {
// Recreate hard links ok = ReplaceFileW(ws1.get(), ws2.get(), nullptr, 0, nullptr, nullptr);
CreateHardLinkW(path.c_str(), ws2.get(), NULL);
} }
if (ok)
{
// Disable the destructor // Disable the destructor
m_path.clear(); m_path.clear();
return true; return true;