Add random number to temp file names

Mitigates against multiple instances trying to write to the same
tmp file at the same time.
This commit is contained in:
Eidolon 2024-04-29 13:38:46 -05:00
parent bc524cd0e9
commit 0025e0fcfa
2 changed files with 4 additions and 2 deletions

View file

@ -287,7 +287,8 @@ void srb2::save_ng_gamedata()
std::string gamedataname_s {gamedatafilename};
fs::path savepath {fmt::format("{}/{}", srb2home, gamedataname_s)};
fs::path tmpsavepath {fmt::format("{}/{}.tmp", srb2home, gamedataname_s)};
int random_number = rand();
fs::path tmpsavepath {fmt::format("{}/{}_{}.tmp", srb2home, gamedataname_s, random_number)};
json ngdata_json = ng;

View file

@ -316,7 +316,8 @@ void PR_SaveProfiles(void)
std::vector<uint8_t> ubjson = json::to_ubjson(ng);
std::string realpath = fmt::format("{}/{}", srb2home, PROFILESFILE);
std::string tmppath = fmt::format("{}.tmp", realpath);
int random_number = rand();
std::string tmppath = fmt::format("{}_{}.tmp", realpath, random_number);
try
{