Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/keepassxreboot/keepassxc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Meyer <apmeyer@bgsu.edu>2020-03-06 06:08:56 +0300
committerJonathan White <support@dmapps.us>2020-05-23 15:44:08 +0300
commit98566fec83bdef9aeb25e70457e4b4879ff4a8a3 (patch)
tree003ae71467f6f7cb15f8e9790567e401325b4882 /src/gui/DatabaseWidget.cpp
parenteb198271acd79310b59bdb415167d72971309760 (diff)
Correct 'save as' behavior to ensure file path remains valid
Copy necessary saving sequence from the save function into saveAs function to prevent inconsistencies when saving to a new file.
Diffstat (limited to 'src/gui/DatabaseWidget.cpp')
-rw-r--r--src/gui/DatabaseWidget.cpp62
1 files changed, 42 insertions, 20 deletions
diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp
index 7664c64b3..2881705bb 100644
--- a/src/gui/DatabaseWidget.cpp
+++ b/src/gui/DatabaseWidget.cpp
@@ -1866,32 +1866,54 @@ bool DatabaseWidget::save()
*/
bool DatabaseWidget::saveAs()
{
- while (true) {
- QString oldFilePath = m_db->filePath();
- if (!QFileInfo::exists(oldFilePath)) {
- oldFilePath = QDir::toNativeSeparators(config()->get(Config::LastDir).toString() + "/"
- + tr("Passwords").append(".kdbx"));
- }
- const QString newFilePath = fileDialog()->getSaveFileName(
- this, tr("Save database as"), oldFilePath, tr("KeePass 2 Database").append(" (*.kdbx)"), nullptr, nullptr);
+ // Never allow saving a locked database; it causes corruption
+ Q_ASSERT(!isLocked());
+ // Release build interlock
+ if (isLocked()) {
+ // We return true since a save is not required
+ return true;
+ }
- if (!newFilePath.isEmpty()) {
- // Ensure we don't recurse back into this function
- m_db->setReadOnly(false);
- m_db->setFilePath(newFilePath);
- m_saveAttempts = 0;
+ QString oldFilePath = m_db->filePath();
+ if (!QFileInfo::exists(oldFilePath)) {
+ oldFilePath =
+ QDir::toNativeSeparators(config()->get(Config::LastDir).toString() + "/" + tr("Passwords").append(".kdbx"));
+ }
+ const QString newFilePath = fileDialog()->getSaveFileName(
+ this, tr("Save database as"), oldFilePath, tr("KeePass 2 Database").append(" (*.kdbx)"), nullptr, nullptr);
- if (!save()) {
- // Failed to save, try again
- continue;
- }
+ bool ok = false;
+ if (!newFilePath.isEmpty()) {
+ auto focusWidget = qApp->focusWidget();
- return true;
+ // Lock out interactions
+ m_entryView->setDisabled(true);
+ m_groupView->setDisabled(true);
+ QApplication::processEvents();
+
+ QString errorMessage;
+ ok = m_db->saveAs(newFilePath,
+ &errorMessage,
+ config()->get(Config::UseAtomicSaves).toBool(),
+ config()->get(Config::BackupBeforeSave).toBool());
+
+ // Return control
+ m_entryView->setDisabled(false);
+ m_groupView->setDisabled(false);
+
+ if (focusWidget) {
+ focusWidget->setFocus();
}
- // Canceled file selection
- return false;
+ if (!ok) {
+ showMessage(tr("Writing the database failed: %1").arg(errorMessage),
+ MessageWidget::Error,
+ true,
+ MessageWidget::LongAutoHideTimeout);
+ }
}
+
+ return ok;
}
/**