From: Christian Kamm Date: Fri, 21 Dec 2018 09:35:07 +0000 (+0100) Subject: Db: Add wiping of pin state for subtrees X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~21^2~468^2~352 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=aa382eda29bd449424b121a691cdb707617921c3;p=nextcloud-desktop.git Db: Add wiping of pin state for subtrees --- diff --git a/src/common/syncjournaldb.cpp b/src/common/syncjournaldb.cpp index f008175f9..d112c64e7 100644 --- a/src/common/syncjournaldb.cpp +++ b/src/common/syncjournaldb.cpp @@ -2136,6 +2136,20 @@ void SyncJournalDb::setPinStateForPath(const QByteArray &path, PinState state) query.exec(); } +void SyncJournalDb::wipePinStateForPathAndBelow(const QByteArray &path) +{ + QMutexLocker lock(&_mutex); + if (!checkConnect()) + return; + + auto &query = _wipePinStateQuery; + ASSERT(query.initOrReset(QByteArrayLiteral( + "DELETE FROM flags WHERE " IS_PREFIX_PATH_OR_EQUAL("?1", "path") ";"), + _db)); + query.bindValue(1, path); + query.exec(); +} + void SyncJournalDb::commit(const QString &context, bool startTrans) { QMutexLocker lock(&_mutex); diff --git a/src/common/syncjournaldb.h b/src/common/syncjournaldb.h index ca589b1d3..525800a08 100644 --- a/src/common/syncjournaldb.h +++ b/src/common/syncjournaldb.h @@ -294,6 +294,13 @@ public: */ void setPinStateForPath(const QByteArray &path, PinState state); + /** + * Wipes pin states for a path and below. + * + * Used when the user asks a subtree to have a particular pin state. + */ + void wipePinStateForPathAndBelow(const QByteArray &path); + /** * Only used for auto-test: * when positive, will decrease the counter for every database operation. @@ -361,6 +368,7 @@ private: SqlQuery _getRawPinStateQuery; SqlQuery _getEffectivePinStateQuery; SqlQuery _setPinStateQuery; + SqlQuery _wipePinStateQuery; /* Storing etags to these folders, or their parent folders, is filtered out. * diff --git a/test/testsyncjournaldb.cpp b/test/testsyncjournaldb.cpp index 03c7a7475..55eca73ad 100644 --- a/test/testsyncjournaldb.cpp +++ b/test/testsyncjournaldb.cpp @@ -336,6 +336,14 @@ private slots: } return *state; }; + auto getRaw = [&](const QByteArray &path) -> PinState { + auto state = _db.rawPinStateForPath(path); + if (!state) { + QTest::qFail("couldn't read pin state", __FILE__, __LINE__); + return PinState::Inherited; + } + return *state; + }; // Make a thrice-nested setup make("local", PinState::AlwaysLocal); @@ -394,6 +402,14 @@ private slots: QCOMPARE(get("online"), PinState::OnlineOnly); QCOMPARE(get("inherit"), PinState::AlwaysLocal); QCOMPARE(get("nonexistant"), PinState::AlwaysLocal); + + // Wiping + QCOMPARE(getRaw("local/local"), PinState::AlwaysLocal); + _db.wipePinStateForPathAndBelow("local/local"); + QCOMPARE(getRaw("local"), PinState::AlwaysLocal); + QCOMPARE(getRaw("local/local"), PinState::Inherited); + QCOMPARE(getRaw("local/local/local"), PinState::Inherited); + QCOMPARE(getRaw("local/local/online"), PinState::Inherited); } private: