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;
}
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)
{
// Always use write flag, remove read flag
@ -758,14 +758,19 @@ namespace fs
{
// Specialization for [const void*, usz] args
f.write(args...);
return true;
}
else
{
// Write args sequentially
(f.write(args), ...);
return true;
}
if constexpr (Flush)
{
f.sync();
}
return true;
}
return false;