mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-03-12 09:06:37 -04:00
Fix saving database backup file
* Fixes #11831 * Also fixes weird issues like saving backup of a backup due to function reuse
This commit is contained in:
parent
33a3796074
commit
418397fb28
@ -2825,6 +2825,10 @@ Disable safe saves and try again?</source>
|
||||
<source>Database file on disk cannot be unlocked with current credentials.<br>Enter new credentials and/or present hardware key to continue.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Failed to save backup database: %1</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>EditEntryWidget</name>
|
||||
|
@ -2615,12 +2615,11 @@ bool DatabaseWidget::performSave(QString& errorMessage, const QString& fileName)
|
||||
*/
|
||||
bool DatabaseWidget::saveBackup()
|
||||
{
|
||||
while (true) {
|
||||
QString oldFilePath = m_db->filePath();
|
||||
if (!QFileInfo::exists(oldFilePath)) {
|
||||
QString defaultFileName = config()->get(Config::DefaultDatabaseFileName).toString();
|
||||
oldFilePath = QDir::toNativeSeparators(
|
||||
FileDialog::getLastDir("db") + "/"
|
||||
oldFilePath =
|
||||
QDir::toNativeSeparators(FileDialog::getLastDir("db") + "/"
|
||||
+ (defaultFileName.isEmpty() ? tr("Passwords").append(".kdbx") : defaultFileName));
|
||||
}
|
||||
|
||||
@ -2629,31 +2628,32 @@ bool DatabaseWidget::saveBackup()
|
||||
FileDialog::getLastDir("backup", oldFilePath),
|
||||
tr("KeePass 2 Database").append(" (*.kdbx)"));
|
||||
|
||||
if (!newFilePath.isEmpty()) {
|
||||
// Ensure we don't recurse back into this function
|
||||
m_db->setFilePath(newFilePath);
|
||||
m_saveAttempts = 0;
|
||||
|
||||
bool modified = m_db->isModified();
|
||||
|
||||
if (!save()) {
|
||||
// Failed to save, try again
|
||||
m_db->setFilePath(oldFilePath);
|
||||
continue;
|
||||
// Early out if we canceled the file selection
|
||||
if (newFilePath.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Record modified state so we can restore after save
|
||||
bool modified = m_db->isModified();
|
||||
|
||||
QString error;
|
||||
bool ok = m_db->saveAs(newFilePath, Database::DirectWrite, {}, &error);
|
||||
|
||||
// Restore database to original state
|
||||
m_db->setFilePath(oldFilePath);
|
||||
if (modified) {
|
||||
// Source database is marked as clean when copy is saved, even if source has unsaved changes
|
||||
m_db->markAsModified();
|
||||
}
|
||||
FileDialog::saveLastDir("backup", newFilePath, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Canceled file selection
|
||||
if (!ok) {
|
||||
// Failed to save backup, post the error
|
||||
showErrorMessage(tr("Failed to save backup database: %1").arg(error));
|
||||
return false;
|
||||
}
|
||||
|
||||
FileDialog::saveLastDir("backup", newFilePath, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
void DatabaseWidget::showMessage(const QString& text,
|
||||
|
Loading…
x
Reference in New Issue
Block a user