JournalDb: add a table in the db for the selective sync

This commit is contained in:
Olivier Goffart 2015-05-20 16:28:06 +02:00
parent 5cb10bf6a1
commit 2c67692958
3 changed files with 76 additions and 1 deletions

View file

@ -207,7 +207,7 @@ int SqlQuery::prepare( const QString& sql)
if( _errId != SQLITE_OK ) {
_error = QString::fromUtf8(sqlite3_errmsg(_db));
qDebug() << "Sqlite prepare statement error:" << _error << "in" <<_sql;
qWarning() << "Sqlite prepare statement error:" << _error << "in" <<_sql;
}
}
return _errId;
@ -260,6 +260,7 @@ bool SqlQuery::next()
void SqlQuery::bindValue(int pos, const QVariant& value)
{
int res = -1;
Q_ASSERT(_stmt);
if( _stmt ) {
switch (value.type()) {
case QVariant::Int:

View file

@ -261,6 +261,17 @@ bool SyncJournalDb::checkConnect()
return sqlFail("Create table poll", createQuery);
}
// create the selectivesync table.
createQuery.prepare("CREATE TABLE IF NOT EXISTS selectivesync ("
"path VARCHAR(4096),"
"type INTEGER"
");");
if (!createQuery.exec()) {
return sqlFail("Create table selectivesync", createQuery);
}
createQuery.prepare("CREATE TABLE IF NOT EXISTS version("
"major INTEGER(8),"
@ -396,6 +407,9 @@ bool SyncJournalDb::checkConnect()
"(path, lastTryEtag, lastTryModtime, retrycount, errorstring, lastTryTime, ignoreDuration) "
"VALUES ( ?1, ?2, ?3, ?4, ?5, ?6, ?7)");
_getSelectiveSyncListQuery.reset(new SqlQuery(_db));
_getSelectiveSyncListQuery->prepare("SELECT path FROM selectivesync WHERE type=?1");
// don't start a new transaction now
commitInternal(QString("checkConnect End"), false);
@ -1245,6 +1259,55 @@ void SyncJournalDb::setPollInfo(const SyncJournalDb::PollInfo& info)
}
}
QStringList SyncJournalDb::selectiveSyncList(SyncJournalDb::SelectiveSyncListType type)
{
QStringList result;
QMutexLocker locker(&_mutex);
if( !checkConnect() ) {
return result;
}
_getSelectiveSyncListQuery->reset();
_getSelectiveSyncListQuery->bindValue(1, int(type));
if (!_getSelectiveSyncListQuery->exec()) {
qWarning() << "SQL query failed: "<< _getSelectiveSyncListQuery->error();
return result;
}
while( _getSelectiveSyncListQuery->next() ) {
auto entry = _getSelectiveSyncListQuery->stringValue(0);
if (!entry.endsWith(QLatin1Char('/'))) {
entry.append(QLatin1Char('/'));
}
result.append(entry);
}
return result;
}
void SyncJournalDb::setSelectiveSyncList(SyncJournalDb::SelectiveSyncListType type, const QStringList& list)
{
QMutexLocker locker(&_mutex);
if( !checkConnect() ) {
return;
}
//first, delete all entries of this type
SqlQuery delQuery("DELETE FROM selectivesync WHERE type == ?1", _db);
delQuery.bindValue(1, int(type));
if( !delQuery.exec() ) {
qWarning() << "SQL error when deleting selective sync list" << list << delQuery.error();
}
SqlQuery insQuery("INSERT INTO selectivesync VALUES (?1, ?2)" , _db);
foreach(const auto &path, list) {
insQuery.bindValue(1, path);
insQuery.bindValue(2, int(type));
if (!insQuery.exec()) {
qWarning() << "SQL error when inserting into selective sync" << type << path << delQuery.error();
}
}
}
void SyncJournalDb::avoidRenamesOnNextSync(const QString& path)
{
QMutexLocker locker(&_mutex);

View file

@ -91,6 +91,16 @@ public:
void setPollInfo(const PollInfo &);
QVector<PollInfo> getPollInfos();
enum SelectiveSyncListType {
SelectiveSyncBlackList = 1,
SelectiveSyncWhiteList = 2,
SelectiveSyncUndecidedList = 3
};
/* return the specified list from the database */
QStringList selectiveSyncList(SelectiveSyncListType type);
/* Write the selective sync list (remove all other entries of that list */
void setSelectiveSyncList(SelectiveSyncListType type, const QStringList &list);
/**
* Make sure that on the next sync, filName is not read from the DB but use the PROPFIND to
* get the info from the server
@ -140,6 +150,7 @@ private:
QScopedPointer<SqlQuery> _deleteFileRecordRecursively;
QScopedPointer<SqlQuery> _getErrorBlacklistQuery;
QScopedPointer<SqlQuery> _setErrorBlacklistQuery;
QScopedPointer<SqlQuery> _getSelectiveSyncListQuery;
/* This is the list of paths we called avoidReadFromDbOnNextSync on.
* It means that they should not be written to the DB in any case since doing