From: Christian Kamm Date: Tue, 23 Apr 2019 11:38:58 +0000 (+0200) Subject: Vfs: Mark sqlite temporaries excluded on db-open #7141 X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~21^2~468^2~240 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=edad7ce7d750531abc746bcd6a1ca14b4746428c;p=nextcloud-desktop.git Vfs: Mark sqlite temporaries excluded on db-open #7141 The previous patch ensured that the sqlite temporaries weren't deleted and recreated for every sync run, but there was still time between client startup and the first sync run where they would have the "needs-sync" icon. --- diff --git a/src/common/syncjournaldb.cpp b/src/common/syncjournaldb.cpp index 1d46332ee..0645ad463 100644 --- a/src/common/syncjournaldb.cpp +++ b/src/common/syncjournaldb.cpp @@ -2325,6 +2325,17 @@ void SyncJournalDb::commitIfNeededAndStartNewTransaction(const QString &context) } } +bool SyncJournalDb::open() +{ + QMutexLocker lock(&_mutex); + return checkConnect(); +} + +bool SyncJournalDb::isOpen() +{ + QMutexLocker lock(&_mutex); + return _db.isOpen(); +} void SyncJournalDb::commitInternal(const QString &context, bool startTrans) { @@ -2341,11 +2352,6 @@ SyncJournalDb::~SyncJournalDb() close(); } -bool SyncJournalDb::isConnected() -{ - QMutexLocker lock(&_mutex); - return checkConnect(); -} bool operator==(const SyncJournalDb::DownloadInfo &lhs, const SyncJournalDb::DownloadInfo &rhs) diff --git a/src/common/syncjournaldb.h b/src/common/syncjournaldb.h index 695d9e040..9ef1e7d72 100644 --- a/src/common/syncjournaldb.h +++ b/src/common/syncjournaldb.h @@ -202,12 +202,20 @@ public: void commit(const QString &context, bool startTrans = true); void commitIfNeededAndStartNewTransaction(const QString &context); - void close(); - - /** - * return true if everything is correct + /** Open the db if it isn't already. + * + * This usually creates some temporary files next to the db file, like + * $dbfile-shm or $dbfile-wal. + * + * returns true if it could be openend or is currently opened. */ - bool isConnected(); + bool open(); + + /** Returns whether the db is currently openend. */ + bool isOpen(); + + /** Close the database */ + void close(); /** * Returns the checksum type for an id. diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp index 8ca941f28..5b5feb9d8 100644 --- a/src/gui/folder.cpp +++ b/src/gui/folder.cpp @@ -497,6 +497,13 @@ void Folder::startVfs() _vfs.data(), &Vfs::fileStatusChanged); _vfs->start(vfsParams); + + // Immediately mark the sqlite temporaries as excluded. They get recreated + // on db-open and need to get marked again every time. + QString stateDbFile = _journal.databaseFilePath(); + _journal.open(); + _vfs->fileStatusChanged(stateDbFile + "-wal", SyncFileStatus::StatusExcluded); + _vfs->fileStatusChanged(stateDbFile + "-shm", SyncFileStatus::StatusExcluded); } int Folder::slotDiscardDownloadProgress() diff --git a/src/libsync/syncengine.cpp b/src/libsync/syncengine.cpp index 98759348a..eecf40fc8 100644 --- a/src/libsync/syncengine.cpp +++ b/src/libsync/syncengine.cpp @@ -481,7 +481,7 @@ void SyncEngine::startSync() qCInfo(lcEngine) << verStr; // This creates the DB if it does not exist yet. - if (!_journal->isConnected()) { + if (!_journal->open()) { qCWarning(lcEngine) << "No way to create a sync journal!"; syncError(tr("Unable to open or create the local sync database. Make sure you have write access in the sync folder.")); finalize(false); @@ -687,7 +687,7 @@ void SyncEngine::slotDiscoveryFinished() qCInfo(lcEngine) << "#### Discovery end #################################################### " << _stopWatch.addLapTime(QLatin1String("Discovery Finished")) << "ms"; // Sanity check - if (!_journal->isConnected()) { + if (!_journal->open()) { qCWarning(lcEngine) << "Bailing out, DB failure"; syncError(tr("Cannot open the sync journal")); finalize(false);