Merge pull request #8750 from leoetlino/close-before-rename

IOS/FS: Fix FST write failure on some platforms
This commit is contained in:
JMC47 2020-04-18 06:50:59 -04:00 committed by GitHub
commit 2d8758daaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 3 deletions

View File

@ -177,9 +177,17 @@ void HostFileSystem::SaveFst()
const std::string dest_path = GetFstFilePath(); const std::string dest_path = GetFstFilePath();
const std::string temp_path = File::GetTempFilenameForAtomicWrite(dest_path); const std::string temp_path = File::GetTempFilenameForAtomicWrite(dest_path);
File::IOFile file{temp_path, "wb"}; {
if (!file.WriteArray(to_write.data(), to_write.size()) || !File::Rename(temp_path, dest_path)) // This temporary file must be closed before it can be renamed.
ERROR_LOG(IOS_FS, "Failed to write new FST"); File::IOFile file{temp_path, "wb"};
if (!file.WriteArray(to_write.data(), to_write.size()))
{
PanicAlert("IOS_FS: Failed to write new FST");
return;
}
}
if (!File::Rename(temp_path, dest_path))
PanicAlert("IOS_FS: Failed to rename temporary FST file");
} }
HostFileSystem::FstEntry* HostFileSystem::GetFstEntryForPath(const std::string& path) HostFileSystem::FstEntry* HostFileSystem::GetFstEntryForPath(const std::string& path)