mirror of
https://github.com/nextcloud/desktop.git
synced 2024-10-24 21:35:47 +03:00
Protect the sync database by a mutex since it is used by the thread
This commit is contained in:
parent
805e1330ad
commit
05fbfb520f
2 changed files with 9 additions and 6 deletions
|
@ -40,6 +40,7 @@ SyncJournalDb::SyncJournalDb(const QString& path, QObject *parent) :
|
|||
|
||||
bool SyncJournalDb::exists()
|
||||
{
|
||||
QMutexLocker locker(&_mutex);
|
||||
return (!_dbFile.isEmpty() && QFile::exists(_dbFile));
|
||||
}
|
||||
|
||||
|
@ -115,6 +116,7 @@ qint64 SyncJournalDb::getPHash(const QString& file) const
|
|||
|
||||
bool SyncJournalDb::setFileRecord( const SyncJournalFileRecord& record )
|
||||
{
|
||||
QMutexLocker locker(&_mutex);
|
||||
qlonglong phash = getPHash(record._path);
|
||||
|
||||
if( checkConnect() ) {
|
||||
|
@ -169,6 +171,7 @@ bool SyncJournalDb::setFileRecord( const SyncJournalFileRecord& record )
|
|||
|
||||
bool SyncJournalDb::deleteFileRecord(const QString& filename)
|
||||
{
|
||||
QMutexLocker locker(&_mutex);
|
||||
qlonglong phash = getPHash(filename);
|
||||
|
||||
if( checkConnect() ) {
|
||||
|
@ -191,6 +194,8 @@ bool SyncJournalDb::deleteFileRecord(const QString& filename)
|
|||
|
||||
SyncJournalFileRecord SyncJournalDb::getFileRecord( const QString& filename )
|
||||
{
|
||||
QMutexLocker locker(&_mutex);
|
||||
|
||||
qlonglong phash = getPHash( filename );
|
||||
SyncJournalFileRecord rec;
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#define SYNCJOURNALDB_H
|
||||
|
||||
#include <QObject>
|
||||
#include <qmutex.h>
|
||||
#include <QSqlDatabase>
|
||||
|
||||
namespace Mirall {
|
||||
|
@ -25,25 +26,22 @@ class SyncJournalDb : public QObject
|
|||
Q_OBJECT
|
||||
public:
|
||||
explicit SyncJournalDb(const QString& path, QObject *parent = 0);
|
||||
|
||||
SyncJournalFileRecord getFileRecord( const QString& filename );
|
||||
|
||||
bool setFileRecord( const SyncJournalFileRecord& record );
|
||||
bool deleteFileRecord( const QString& filename );
|
||||
int getFileRecordCount();
|
||||
|
||||
QSqlDatabase *getDB(){ return &_db; }
|
||||
bool exists();
|
||||
bool checkConnect();
|
||||
qint64 getPHash(const QString& ) const;
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
private:
|
||||
qint64 getPHash(const QString& ) const;
|
||||
bool checkConnect();
|
||||
QSqlDatabase _db;
|
||||
QString _dbFile;
|
||||
QMutex _mutex; // Public functions are protected with the mutex.
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue