1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-25 04:02:42 +01:00

Fix atomicity of savedata/trophy data writes

This commit is contained in:
Eladash 2021-02-22 14:36:35 +02:00 committed by Ivan
parent 932f31e37b
commit d4af8dd89a
3 changed files with 10 additions and 5 deletions

View File

@ -748,7 +748,7 @@ namespace fs
return result; return result;
} }
template <typename... Args> template <bool Flush = false, typename... Args>
bool write_file(const std::string& path, bs_t<fs::open_mode> mode, const Args&... args) bool write_file(const std::string& path, bs_t<fs::open_mode> mode, const Args&... args)
{ {
// Always use write flag, remove read flag // Always use write flag, remove read flag
@ -758,14 +758,19 @@ namespace fs
{ {
// Specialization for [const void*, usz] args // Specialization for [const void*, usz] args
f.write(args...); f.write(args...);
return true;
} }
else else
{ {
// Write args sequentially // Write args sequentially
(f.write(args), ...); (f.write(args), ...);
return true;
} }
if constexpr (Flush)
{
f.sync();
}
return true;
} }
return false; return false;

View File

@ -1911,7 +1911,7 @@ static NEVER_INLINE error_code savedata_op(ppu_thread& ppu, u32 operation, u32 v
if (auto file = pair.second.release()) if (auto file = pair.second.release())
{ {
auto fvec = static_cast<fs::container_stream<std::vector<uchar>>&>(*file); auto fvec = static_cast<fs::container_stream<std::vector<uchar>>&>(*file);
fs::file(new_path + vfs::escape(pair.first), fs::rewrite).write(fvec.obj); ensure(fs::write_file<true>(new_path + vfs::escape(pair.first), fs::rewrite, fvec.obj));
} }
} }

View File

@ -47,7 +47,7 @@ bool TRPLoader::Install(const std::string& dest, bool show)
} }
// Create the file in the temporary directory // Create the file in the temporary directory
success = fs::write_file(temp + '/' + vfs::escape(entry.name), fs::create + fs::excl, buffer); success = fs::write_file<true>(temp + '/' + vfs::escape(entry.name), fs::create + fs::excl, buffer);
if (!success) if (!success)
{ {
break; break;