mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-01-27 14:57:09 -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
|
* 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
|
* @param filePath Path to the file to backup
|
||||||
* @return true on success
|
* @return true on success
|
||||||
*/
|
*/
|
||||||
bool Database::backupDatabase(const QString& filePath)
|
bool Database::backupDatabase(const QString& filePath)
|
||||||
{
|
{
|
||||||
QString backupFilePath = filePath;
|
static auto re = QRegularExpression("(\\.[^.]+)$");
|
||||||
auto re = QRegularExpression("\\.kdbx$|(?<!\\.kdbx)$", QRegularExpression::CaseInsensitiveOption);
|
|
||||||
backupFilePath.replace(re, ".old.kdbx");
|
auto match = re.match(filePath);
|
||||||
|
auto backupFilePath = filePath;
|
||||||
|
backupFilePath = backupFilePath.replace(re, "") + ".old" + match.captured(1);
|
||||||
QFile::remove(backupFilePath);
|
QFile::remove(backupFilePath);
|
||||||
return QFile::copy(filePath, backupFilePath);
|
return QFile::copy(filePath, backupFilePath);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user