FileSystem: Fix FD leak with atomic updated file on Linux

Also add the ability to explicitly commit and check for errors.
This commit is contained in:
Stenzek
2024-09-03 20:43:10 +10:00
parent 1eb1b03141
commit 87eded4bce
5 changed files with 71 additions and 20 deletions

View File

@ -2910,7 +2910,7 @@ bool System::SaveState(const char* path, Error* error, bool backup_existing_save
}
}
auto fp = FileSystem::CreateAtomicRenamedFile(path, "wb", error);
auto fp = FileSystem::CreateAtomicRenamedFile(path, error);
if (!fp)
{
Error::AddPrefixFmt(error, "Cannot open '{}': ", Path::GetFileName(path));
@ -2930,7 +2930,7 @@ bool System::SaveState(const char* path, Error* error, bool backup_existing_save
5.0f);
VERBOSE_LOG("Saving state took {:.2f} msec", save_timer.GetTimeMilliseconds());
return true;
return FileSystem::CommitAtomicRenamedFile(fp, error);
}
bool System::SaveStateToBuffer(SaveStateBuffer* buffer, Error* error, u32 screenshot_size /* = 256 */)