diff options
author | Hannah von Reth <hannah.vonreth@owncloud.com> | 2022-06-21 15:57:36 +0300 |
---|---|---|
committer | Hannah von Reth <vonreth@kde.org> | 2022-06-30 14:29:47 +0300 |
commit | 39e0b82df6d67eb669c003d267f9b7ef897b846c (patch) | |
tree | f20cfdf001e5cf953ae7cdd6799200055f59304e /src/common | |
parent | 2dd730d466dc1b2a2a244cacb066a2db2cbb65f4 (diff) |
Don't recreate db after it was closed
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/syncjournaldb.cpp | 10 | ||||
-rw-r--r-- | src/common/syncjournaldb.h | 11 |
2 files changed, 21 insertions, 0 deletions
diff --git a/src/common/syncjournaldb.cpp b/src/common/syncjournaldb.cpp index b79a038b5..6bafbaa62 100644 --- a/src/common/syncjournaldb.cpp +++ b/src/common/syncjournaldb.cpp @@ -250,6 +250,10 @@ bool SyncJournalDb::sqlFail(const QString &log, const SqlQuery &query) bool SyncJournalDb::checkConnect() { + if (_closed) { + qCWarning(lcDb) << Q_FUNC_INFO << "after the db was closed"; + return false; + } if (autotestFailCounter >= 0) { if (!autotestFailCounter--) { qCInfo(lcDb) << "Error Simulated"; @@ -625,8 +629,14 @@ void SyncJournalDb::close() _db.close(); clearEtagStorageFilter(); _metadataTableIsEmpty = false; + _closed = true; } +void SyncJournalDb::allowReopen() +{ + Q_ASSERT(_closed); + _closed = false; +} bool SyncJournalDb::updateDatabaseStructure() { diff --git a/src/common/syncjournaldb.h b/src/common/syncjournaldb.h index 933fcbbee..ad68c7f11 100644 --- a/src/common/syncjournaldb.h +++ b/src/common/syncjournaldb.h @@ -220,6 +220,12 @@ public: void close(); /** + * allow to reopen/recreate the db after it was closed (unit tests) + * This is usually not allowed to prevent accidential recreation of db. + */ + void allowReopen(); + + /** * Returns the checksum type for an id. */ QByteArray getChecksumType(int checksumTypeId); @@ -413,6 +419,11 @@ private: QByteArray _journalMode; PreparedSqlQueryManager _queryManager; + + /** + * Whether the db was already closed, prevent recreation + */ + bool _closed = false; }; bool OCSYNC_EXPORT |