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:
authorJonathan White <support@dmapps.us>2019-12-13 06:40:17 +0300
committerJonathan White <support@dmapps.us>2019-12-15 05:26:12 +0300
commit8e76c30dd104ce8044ecf0c53176f0f716e55f29 (patch)
tree32d4248e7f17034b06851162f0213721c759609f /src/core/FileWatcher.cpp
parentf9cb2bd5dfaf58b3fd45272e8b0427aa0d71b0fa (diff)
Prevent reloading database while editing an entry or group
* Fix #3933 and fix #3857. Interaction with entries and groups is disabled while the database is being reloaded or saved to prevent changes from occurring. Prevent the database from being reloading if an entry or group is currently being edited. * Fix #3941 - Only notify components when the database file actually changes (determined by checksum). This prevents spurious merge requests when the file is merely touched by another service (e.g., DropBox). * Fix code format of ElidedLabel.cpp
Diffstat (limited to 'src/core/FileWatcher.cpp')
-rw-r--r--src/core/FileWatcher.cpp30
1 files changed, 13 insertions, 17 deletions
diff --git a/src/core/FileWatcher.cpp b/src/core/FileWatcher.cpp
index 0d1def31a..fb8e95128 100644
--- a/src/core/FileWatcher.cpp
+++ b/src/core/FileWatcher.cpp
@@ -35,11 +35,10 @@ namespace
FileWatcher::FileWatcher(QObject* parent)
: QObject(parent)
- , m_ignoreFileChange(false)
{
- connect(&m_fileWatcher, SIGNAL(fileChanged(QString)), SLOT(onWatchedFileChanged()));
+ connect(&m_fileWatcher, SIGNAL(fileChanged(QString)), SLOT(checkFileChanged()));
+ connect(&m_fileChecksumTimer, SIGNAL(timeout()), SLOT(checkFileChanged()));
connect(&m_fileChangeDelayTimer, SIGNAL(timeout()), SIGNAL(fileChanged()));
- connect(&m_fileChecksumTimer, SIGNAL(timeout()), SLOT(checkFileChecksum()));
m_fileChangeDelayTimer.setSingleShot(true);
m_fileIgnoreDelayTimer.setSingleShot(true);
}
@@ -101,17 +100,6 @@ void FileWatcher::resume()
}
}
-void FileWatcher::onWatchedFileChanged()
-{
- // Don't notify if we are ignoring events or already started a notification chain
- if (shouldIgnoreChanges()) {
- return;
- }
-
- m_fileChecksum = calculateChecksum();
- m_fileChangeDelayTimer.start(0);
-}
-
bool FileWatcher::shouldIgnoreChanges()
{
return m_filePath.isEmpty() || m_ignoreFileChange || m_fileIgnoreDelayTimer.isActive()
@@ -123,15 +111,23 @@ bool FileWatcher::hasSameFileChecksum()
return calculateChecksum() == m_fileChecksum;
}
-void FileWatcher::checkFileChecksum()
+void FileWatcher::checkFileChanged()
{
if (shouldIgnoreChanges()) {
return;
}
- if (!hasSameFileChecksum()) {
- onWatchedFileChanged();
+ // Prevent reentrance
+ m_ignoreFileChange = true;
+
+ // Only trigger the change notice if there is a checksum mismatch
+ auto checksum = calculateChecksum();
+ if (checksum != m_fileChecksum) {
+ m_fileChecksum = checksum;
+ m_fileChangeDelayTimer.start(0);
}
+
+ m_ignoreFileChange = false;
}
QByteArray FileWatcher::calculateChecksum()