[Pkg-owncloud-commits] [owncloud-client] 107/498: JournalDb: add a table in the db for the selective sync
Sandro Knauß
hefee-guest at moszumanska.debian.org
Tue Aug 11 14:48:40 UTC 2015
This is an automated email from the git hooks/post-receive script.
hefee-guest pushed a commit to branch master
in repository owncloud-client.
commit 2c67692958803d98c7c8277f1980f310b5fed79a
Author: Olivier Goffart <ogoffart at woboq.com>
Date: Wed May 20 16:28:06 2015 +0200
JournalDb: add a table in the db for the selective sync
---
src/libsync/ownsql.cpp | 3 ++-
src/libsync/syncjournaldb.cpp | 63 +++++++++++++++++++++++++++++++++++++++++++
src/libsync/syncjournaldb.h | 11 ++++++++
3 files changed, 76 insertions(+), 1 deletion(-)
diff --git a/src/libsync/ownsql.cpp b/src/libsync/ownsql.cpp
index 0aba756..6bb3d5c 100644
--- a/src/libsync/ownsql.cpp
+++ b/src/libsync/ownsql.cpp
@@ -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:
diff --git a/src/libsync/syncjournaldb.cpp b/src/libsync/syncjournaldb.cpp
index 9298a12..eebd3ef 100644
--- a/src/libsync/syncjournaldb.cpp
+++ b/src/libsync/syncjournaldb.cpp
@@ -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);
diff --git a/src/libsync/syncjournaldb.h b/src/libsync/syncjournaldb.h
index 6074631..fcbc155 100644
--- a/src/libsync/syncjournaldb.h
+++ b/src/libsync/syncjournaldb.h
@@ -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
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git
More information about the Pkg-owncloud-commits
mailing list