Skip to content

Commit

Permalink
timestamp the backup file
Browse files Browse the repository at this point in the history
  • Loading branch information
carlos-zamora committed Nov 6, 2020
1 parent 396c1a1 commit c4f2733
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1038,15 +1038,21 @@ const Json::Value& CascadiaSettings::_GetDisabledProfileSourcesJsonObject(const
}

// Method Description:
// - Create a backup file with the current contents, iff one does not exist
// - Create a timestamped backup file with the current contents
// Arguments:
// - content - the content that we're writing to the backup file
// - settingsPath - the path to the settings file that we're going to create a backup for
// Return Value:
// - <none>
void CascadiaSettings::_WriteBackupFile(std::string_view content, const winrt::hstring settingsPath)
{
const auto backupSettingsPath{ settingsPath + L".backup" };
// create a timestamped backup file
time_t timeStamp;
tm localTimeStamp;
time(&timeStamp);
localtime_s(&localTimeStamp, &timeStamp);
const auto backupSettingsPath{ fmt::format(L"{}{}{}{}{}{}.backup", settingsPath, localTimeStamp.tm_year, localTimeStamp.tm_mon, localTimeStamp.tm_mday, localTimeStamp.tm_hour, localTimeStamp.tm_min, localTimeStamp.tm_sec) };

wil::unique_hfile backupFile{ CreateFileW(backupSettingsPath.c_str(),
GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
Expand Down

1 comment on commit c4f2733

@github-actions

This comment was marked as resolved.

Please sign in to comment.