Telemetry: Rename old file instead of copying

Since we do an immediate overwrite of the file we are copying, we can
instead do a rename. Failure on rename is fine, will either mean the
telemetry file didn't exist initially, or some other permission error so
the telemetry will get lost regardless.
This commit is contained in:
Ryan Houdek 2024-03-21 20:58:00 -07:00
parent 8852d94416
commit 4952b2e16c
No known key found for this signature in database

View File

@ -61,11 +61,11 @@ namespace FEXCore::Telemetry {
auto DataDirectory = Config::GetDataDirectory();
DataDirectory += "Telemetry/" + ApplicationName + ".telem";
if (FHU::Filesystem::Exists(DataDirectory)) {
// If the file exists, retain a single backup
auto Backup = DataDirectory + ".1";
FHU::Filesystem::CopyFile(DataDirectory, Backup, FHU::Filesystem::CopyOptions::OVERWRITE_EXISTING);
}
// Retain a single backup if the telemetry already existed.
auto Backup = DataDirectory + ".bck";
// Failure on rename is okay.
(void)FHU::Filesystem::RenameFile(DataDirectory, Backup);
auto File = FEXCore::File::File(DataDirectory.c_str(),
FEXCore::File::FileModes::WRITE |