From 7a7b168af312d2d7f841b99a10602e8168f28851 Mon Sep 17 00:00:00 2001 From: Eladash Date: Sat, 13 Mar 2021 08:19:22 +0200 Subject: [PATCH] GUI: Atomic RAP file installation --- rpcs3/rpcs3qt/main_window.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/rpcs3/rpcs3qt/main_window.cpp b/rpcs3/rpcs3qt/main_window.cpp index bfe83bdb7..292d34d85 100644 --- a/rpcs3/rpcs3qt/main_window.cpp +++ b/rpcs3/rpcs3qt/main_window.cpp @@ -516,7 +516,25 @@ bool main_window::InstallRapFile(const QString& path, const std::string& filenam return false; } - return fs::copy_file(sstr(path), Emulator::GetHddDir() + "/home/" + Emu.GetUsr() + "/exdata/" + filename.substr(0, filename.find_last_of('.')) + ".rap", true); + // Copy file atomically with thread/process-safe error checking for file size + + fs::pending_file to(Emulator::GetHddDir() + "/home/" + Emu.GetUsr() + "/exdata/" + filename.substr(0, filename.find_last_of('.')) + ".rap"); + fs::file from(sstr(path)); + + if (!to.file || !from) + { + return false; + } + + to.file.write(from.to_vector()); + + if (to.file.size() < 0x10) + { + // Not a RAP file + return false; + } + + return to.commit(); } void main_window::InstallPackages(QStringList file_paths)