vfs: Allow retrieving of pin state paths and flags

This commit is contained in:
Christian Kamm 2019-01-08 15:15:17 +01:00 committed by Kevin Ottens
parent 7ef6e60660
commit 20ef0a0290
No known key found for this signature in database
GPG key ID: 074BBBCB8DECC9E2
3 changed files with 38 additions and 3 deletions

View file

@ -2167,6 +2167,22 @@ void SyncJournalDb::wipePinStateForPathAndBelow(const QByteArray &path)
query.exec();
}
Optional<QVector<QPair<QByteArray, PinState>>> SyncJournalDb::rawPinStates()
{
QMutexLocker lock(&_mutex);
if (!checkConnect())
return {};
SqlQuery query("SELECT path, pinState FROM flags;", _db);
query.exec();
QVector<QPair<QByteArray, PinState>> result;
while (query.next()) {
result.append({ query.baValue(0), static_cast<PinState>(query.intValue(1)) });
}
return result;
}
void SyncJournalDb::commit(const QString &context, bool startTrans)
{
QMutexLocker lock(&_mutex);

View file

@ -304,6 +304,13 @@ public:
*/
void wipePinStateForPathAndBelow(const QByteArray &path);
/**
* Returns list of all paths with their pin state as in the db.
*
* Returns nothing on db error.
*/
Optional<QVector<QPair<QByteArray, PinState>>> rawPinStates();
/**
* Only used for auto-test:
* when positive, will decrease the counter for every database operation.

View file

@ -345,7 +345,12 @@ private slots:
return *state;
};
_db.wipePinStateForPathAndBelow("");
auto list = _db.rawPinStates();
QCOMPARE(list->size(), 0);
// Make a thrice-nested setup
make("", PinState::AlwaysLocal);
make("local", PinState::AlwaysLocal);
make("online", PinState::OnlineOnly);
make("inherit", PinState::Inherited);
@ -355,12 +360,15 @@ private slots:
make(QByteArray(base) + "online", PinState::OnlineOnly);
for (auto base2 : {"local/", "online/", "inherit/"}) {
make(QByteArray(base) + base2 + "/inherit", PinState::Inherited);
make(QByteArray(base) + base2 + "/local", PinState::AlwaysLocal);
make(QByteArray(base) + base2 + "/online", PinState::OnlineOnly);
make(QByteArray(base) + base2 + "inherit", PinState::Inherited);
make(QByteArray(base) + base2 + "local", PinState::AlwaysLocal);
make(QByteArray(base) + base2 + "online", PinState::OnlineOnly);
}
}
list = _db.rawPinStates();
QCOMPARE(list->size(), 4 + 9 + 27);
// Baseline direct checks (the fallback for unset root pinstate is AlwaysLocal)
QCOMPARE(get("local"), PinState::AlwaysLocal);
QCOMPARE(get("online"), PinState::OnlineOnly);
@ -410,12 +418,16 @@ private slots:
QCOMPARE(getRaw("local/local"), PinState::Inherited);
QCOMPARE(getRaw("local/local/local"), PinState::Inherited);
QCOMPARE(getRaw("local/local/online"), PinState::Inherited);
list = _db.rawPinStates();
QCOMPARE(list->size(), 4 + 9 + 27 - 4);
// Wiping everything
_db.wipePinStateForPathAndBelow("");
QCOMPARE(getRaw(""), PinState::Inherited);
QCOMPARE(getRaw("local"), PinState::Inherited);
QCOMPARE(getRaw("online"), PinState::Inherited);
list = _db.rawPinStates();
QCOMPARE(list->size(), 0);
}
private: