[Pkg-owncloud-commits] [owncloud-client] 08/115: Selective sync: ignore the files that are not in the selective sync white list
Sandro Knauß
hefee-guest at moszumanska.debian.org
Fri Aug 29 22:03:53 UTC 2014
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 7e009667a2349edb05e1611737de5dc90fb00d8d
Author: Olivier Goffart <ogoffart at woboq.com>
Date: Mon Aug 11 18:41:42 2014 +0200
Selective sync: ignore the files that are not in the selective sync white list
---
csync/src/csync_exclude.c | 6 ++++++
csync/src/csync_private.h | 4 ++++
src/mirall/accountsettings.cpp | 2 +-
src/mirall/discoveryphase.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++
src/mirall/discoveryphase.h | 13 +++++++++++-
src/mirall/folder.cpp | 1 +
src/mirall/syncengine.cpp | 1 +
src/mirall/syncengine.h | 6 ++++++
8 files changed, 78 insertions(+), 2 deletions(-)
diff --git a/csync/src/csync_exclude.c b/csync/src/csync_exclude.c
index 25cd060..09af946 100644
--- a/csync/src/csync_exclude.c
+++ b/csync/src/csync_exclude.c
@@ -310,6 +310,12 @@ CSYNC_EXCLUDE_TYPE csync_excluded(CSYNC *ctx, const char *path, int filetype) {
SAFE_FREE(dname);
}
+ if (match == CSYNC_NOT_EXCLUDED && ctx->checkWhiteListHook) {
+ if (ctx->checkWhiteListHook(ctx->checkWhiteListData, path)) {
+ match = CSYNC_FILE_SILENTLY_EXCLUDED;
+ }
+ }
+
out:
return match;
diff --git a/csync/src/csync_private.h b/csync/src/csync_private.h
index 2e3674b..e2da3ea 100644
--- a/csync/src/csync_private.h
+++ b/csync/src/csync_private.h
@@ -144,6 +144,10 @@ struct csync_s {
int read_from_db_disabled;
struct csync_owncloud_ctx_s *owncloud_context;
+
+ /* hooks for checking the white list */
+ void *checkWhiteListData;
+ int (*checkWhiteListHook)(void*, const char*);
};
diff --git a/src/mirall/accountsettings.cpp b/src/mirall/accountsettings.cpp
index 4db0c28..f76d5a4 100644
--- a/src/mirall/accountsettings.cpp
+++ b/src/mirall/accountsettings.cpp
@@ -381,7 +381,7 @@ void AccountSettings::slotSelectiveSync()
FolderMan *folderMan = FolderMan::instance();
Folder *f = folderMan->folder(alias);
if (f) {
- (new SelectiveSyncDialog(f, this))->show();
+ (new SelectiveSyncDialog(f, this))->open();
}
}
diff --git a/src/mirall/discoveryphase.cpp b/src/mirall/discoveryphase.cpp
index b1e3d16..b1e485a 100644
--- a/src/mirall/discoveryphase.cpp
+++ b/src/mirall/discoveryphase.cpp
@@ -13,8 +13,55 @@
*/
#include "discoveryphase.h"
+#include <csync_private.h>
+
+bool DiscoveryJob::isInWhiteList(const QString& path_) const
+{
+ if (_selectiveSyncWhiteList.isEmpty()) {
+ // If there is no white list, everything is allowed
+ return true;
+ }
+
+ // If the path is a prefix of any item of the list, this means we need to go deeper, so we sync.
+ // (this means it was partially checked)
+ // If one of the item in the white list is a prefix of the path, it means this path need to
+ // be synced.
+ //
+ // We know the list is sorted (for it is done in DiscoveryJob::start)
+ // So we can do a binary search. If the path is a prefix if another item, this item will be
+ // equal, or right after in the lexical order.
+ // If an item has the path as a prefix, it will be right before in the lexicographic order.
+
+ QString path = path_ + QLatin1Char('/');
+
+ auto it = std::lower_bound(_selectiveSyncWhiteList.begin(), _selectiveSyncWhiteList.end(), path);
+ if (it != _selectiveSyncWhiteList.end() && path.startsWith(*it)) {
+ // If the path is a prefix of something in the white list, we need to sync the contents
+ return true;
+ }
+
+ // If the item before is a prefix of the path, we are also good
+ if (it == _selectiveSyncWhiteList.begin()) {
+ return false;
+ }
+ --it;
+ if ((*it).startsWith(path)) {
+ return true;
+ }
+
+ return false;
+}
+
+int DiscoveryJob::isInWhiteListCallBack(void *data, const char *path)
+{
+ return static_cast<DiscoveryJob*>(data)->isInWhiteList(QString::fromUtf8(path));
+}
+
void DiscoveryJob::start() {
+ _selectiveSyncWhiteList.sort();
+ _csync_ctx->checkWhiteListHook = isInWhiteListCallBack;
+ _csync_ctx->checkWhiteListData = this;
csync_set_log_callback(_log_callback);
csync_set_log_level(_log_level);
csync_set_log_userdata(_log_userdata);
diff --git a/src/mirall/discoveryphase.h b/src/mirall/discoveryphase.h
index 949794c..2044b62 100644
--- a/src/mirall/discoveryphase.h
+++ b/src/mirall/discoveryphase.h
@@ -15,6 +15,7 @@
#pragma once
#include <QObject>
+#include <QStringList>
#include <csync.h>
/**
@@ -29,7 +30,14 @@ class DiscoveryJob : public QObject {
csync_log_callback _log_callback;
int _log_level;
void* _log_userdata;
- Q_INVOKABLE void start();
+
+ /**
+ * return true if the given path should be synced,
+ * false if the path should be ignored
+ */
+ bool isInWhiteList(const QString &path) const;
+ static int isInWhiteListCallBack(void *, const char *);
+
public:
explicit DiscoveryJob(CSYNC *ctx, QObject* parent = 0)
: QObject(parent), _csync_ctx(ctx) {
@@ -39,6 +47,9 @@ public:
_log_level = csync_get_log_level();
_log_userdata = csync_get_log_userdata();
}
+
+ QStringList _selectiveSyncWhiteList;
+ Q_INVOKABLE void start();
signals:
void finished(int result);
};
diff --git a/src/mirall/folder.cpp b/src/mirall/folder.cpp
index 7e78fde..736fa63 100644
--- a/src/mirall/folder.cpp
+++ b/src/mirall/folder.cpp
@@ -596,6 +596,7 @@ void Folder::startSync(const QStringList &pathList)
connect(_engine.data(), SIGNAL(jobCompleted(SyncFileItem)), this, SLOT(slotJobCompleted(SyncFileItem)));
setDirtyNetworkLimits();
+ _engine->setSelectiveSyncWhiteList(selectiveSyncList());
QMetaObject::invokeMethod(_engine.data(), "startSync", Qt::QueuedConnection);
diff --git a/src/mirall/syncengine.cpp b/src/mirall/syncengine.cpp
index cfff3de..8cc3ebc 100644
--- a/src/mirall/syncengine.cpp
+++ b/src/mirall/syncengine.cpp
@@ -533,6 +533,7 @@ void SyncEngine::startSync()
qDebug() << "#### Discovery start #################################################### >>";
DiscoveryJob *job = new DiscoveryJob(_csync_ctx);
+ job->_selectiveSyncWhiteList = _selectiveSyncWhiteList;
job->moveToThread(&_thread);
connect(job, SIGNAL(finished(int)), this, SLOT(slotDiscoveryJobFinished(int)));
QMetaObject::invokeMethod(job, "start", Qt::QueuedConnection);
diff --git a/src/mirall/syncengine.h b/src/mirall/syncengine.h
index ac3df81..71b4505 100644
--- a/src/mirall/syncengine.h
+++ b/src/mirall/syncengine.h
@@ -24,6 +24,7 @@
#include <QSet>
#include <QMap>
#include <qelapsedtimer.h>
+#include <QStringList>
#include <csync.h>
@@ -58,6 +59,9 @@ public:
Utility::StopWatch &stopWatch() { return _stopWatch; }
+ void setSelectiveSyncWhiteList(const QStringList &list)
+ { _selectiveSyncWhiteList = list; }
+
signals:
void csyncError( const QString& );
void csyncUnavailable();
@@ -139,6 +143,8 @@ private:
// hash containing the permissions on the remote directory
QHash<QString, QByteArray> _remotePerms;
+
+ QStringList _selectiveSyncWhiteList;
};
--
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