diff --git a/src/core/Database.cpp b/src/core/Database.cpp index 7a10f0483..508cbe51c 100644 --- a/src/core/Database.cpp +++ b/src/core/Database.cpp @@ -253,9 +253,6 @@ bool Database::saveAs(const QString& filePath, SaveAction action, const QString& return false; } - // Prevent destructive operations while saving - QMutexLocker locker(&m_saveMutex); - if (filePath == m_data.filePath) { // Fail-safe check to make sure we don't overwrite underlying file changes // that have not yet triggered a file reload/merge operation. @@ -270,6 +267,9 @@ bool Database::saveAs(const QString& filePath, SaveAction action, const QString& // Clear read-only flag m_fileWatcher->stop(); + // Prevent destructive operations while saving + QMutexLocker locker(&m_saveMutex); + QFileInfo fileInfo(filePath); auto realFilePath = fileInfo.exists() ? fileInfo.canonicalFilePath() : fileInfo.absoluteFilePath(); bool isNewFile = !QFile::exists(realFilePath); @@ -463,6 +463,7 @@ bool Database::import(const QString& xmlExportPath, QString* error) void Database::releaseData() { // Prevent data release while saving + Q_ASSERT(!isSaving()); QMutexLocker locker(&m_saveMutex); if (m_modified) { diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index 64b4c4c77..ec5705914 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -1747,8 +1747,8 @@ bool DatabaseWidget::lock() void DatabaseWidget::reloadDatabaseFile() { - // Ignore reload if we are locked or currently editing an entry or group - if (!m_db || isLocked() || isEntryEditActive() || isGroupEditActive()) { + // Ignore reload if we are locked, saving, or currently editing an entry or group + if (!m_db || isLocked() || isEntryEditActive() || isGroupEditActive() || isSaving()) { return; }