mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-12-25 15:29:44 -05:00
Use existing extension when creating backup file
* passwords.kdbx -> passwords.old.kdbx * passwords.db -> passwords.old.db * passwords -> passwords.old
This commit is contained in:
parent
14e868d2f7
commit
e20d652cca
@ -304,16 +304,18 @@ bool Database::writeDatabase(QIODevice* device, QString* error)
|
||||
|
||||
/**
|
||||
* Remove the old backup and replace it with a new one
|
||||
* backups are named <filename>.old.kdbx
|
||||
* backups are named <filename>.old.<extension>
|
||||
*
|
||||
* @param filePath Path to the file to backup
|
||||
* @return true on success
|
||||
*/
|
||||
bool Database::backupDatabase(const QString& filePath)
|
||||
{
|
||||
QString backupFilePath = filePath;
|
||||
auto re = QRegularExpression("\\.kdbx$|(?<!\\.kdbx)$", QRegularExpression::CaseInsensitiveOption);
|
||||
backupFilePath.replace(re, ".old.kdbx");
|
||||
static auto re = QRegularExpression("(\\.[^.]+)$");
|
||||
|
||||
auto match = re.match(filePath);
|
||||
auto backupFilePath = filePath;
|
||||
backupFilePath = backupFilePath.replace(re, "") + ".old" + match.captured(1);
|
||||
QFile::remove(backupFilePath);
|
||||
return QFile::copy(filePath, backupFilePath);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user