Vfs: Mark sqlite temporaries excluded on db-open #7141
authorChristian Kamm <mail@ckamm.de>
Tue, 23 Apr 2019 11:38:58 +0000 (13:38 +0200)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:58:50 +0000 (10:58 +0100)
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.

src/common/syncjournaldb.cpp
src/common/syncjournaldb.h
src/gui/folder.cpp
src/libsync/syncengine.cpp

index 1d46332eed5f0f037f9b4483ecc5a90296e5e395..0645ad4633aa6f2542ce891af365aca44cb64e2f 100644 (file)
@@ -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)
index 695d9e040b5e363f61388a8ad24f3dd705b33efa..9ef1e7d72e1da91e90acbcf4f3230c236dbebe73 100644 (file)
@@ -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.
index 8ca941f28745437075016ef07cc403ffd33666a1..5b5feb9d820cb871726fd462295ddc2fc973deed 100644 (file)
@@ -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()
index 98759348a54ae85b18e13da339ec455f36f90509..eecf40fc8a6d295a8a3192a745acb1a409f9964a 100644 (file)
@@ -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);