[Pkg-owncloud-commits] [owncloud-client] 36/115: Selective sync: use a black list instead of a white list
Sandro Knauß
hefee-guest at moszumanska.debian.org
Fri Aug 29 22:03:57 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 c1831f4946a2f88c7365cb618c283a47f813fd78
Author: Olivier Goffart <ogoffart at woboq.com>
Date: Fri Aug 15 12:29:10 2014 +0200
Selective sync: use a black list instead of a white list
---
csync/src/csync_exclude.c | 4 ++--
csync/src/csync_private.h | 4 ++--
src/mirall/discoveryphase.cpp | 33 ++++++++++++---------------------
src/mirall/discoveryphase.h | 4 ++--
src/mirall/folder.cpp | 2 +-
src/mirall/folder.h | 8 ++++----
src/mirall/folderman.cpp | 4 ++--
src/mirall/selectivesyncdialog.cpp | 24 ++++++++++++------------
src/mirall/selectivesyncdialog.h | 2 +-
src/mirall/syncengine.cpp | 2 +-
src/mirall/syncengine.h | 2 +-
11 files changed, 40 insertions(+), 49 deletions(-)
diff --git a/csync/src/csync_exclude.c b/csync/src/csync_exclude.c
index 0458795..eb97eea 100644
--- a/csync/src/csync_exclude.c
+++ b/csync/src/csync_exclude.c
@@ -313,8 +313,8 @@ 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)) {
+ if (match == CSYNC_NOT_EXCLUDED && ctx->checkBlackListHook) {
+ if (ctx->checkBlackListHook(ctx->checkBlackListData, path)) {
match = CSYNC_FILE_EXCLUDE_LIST;
}
}
diff --git a/csync/src/csync_private.h b/csync/src/csync_private.h
index e2da3ea..80b4053 100644
--- a/csync/src/csync_private.h
+++ b/csync/src/csync_private.h
@@ -146,8 +146,8 @@ struct csync_s {
struct csync_owncloud_ctx_s *owncloud_context;
/* hooks for checking the white list */
- void *checkWhiteListData;
- int (*checkWhiteListHook)(void*, const char*);
+ void *checkBlackListData;
+ int (*checkBlackListHook)(void*, const char*);
};
diff --git a/src/mirall/discoveryphase.cpp b/src/mirall/discoveryphase.cpp
index 8cd5860..1b9c754 100644
--- a/src/mirall/discoveryphase.cpp
+++ b/src/mirall/discoveryphase.cpp
@@ -16,33 +16,24 @@
#include <csync_private.h>
#include <qdebug.h>
-bool DiscoveryJob::isInWhiteList(const QString& path) const
+bool DiscoveryJob::isInBlackList(const QString& path) const
{
- if (_selectiveSyncWhiteList.isEmpty()) {
- // If there is no white list, everything is allowed
- return true;
+ if (_selectiveSyncBlackList.isEmpty()) {
+ // If there is no black list, everything is allowed
+ return false;
}
- // 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
+ // If one of the item in the black list is a prefix of the path, it means this path need not 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.
+ // So we can do a binary search. If the path is a prefix if another item or right after in the lexical order.
QString pathSlash = path + QLatin1Char('/');
- auto it = std::lower_bound(_selectiveSyncWhiteList.begin(), _selectiveSyncWhiteList.end(), pathSlash);
- if (it != _selectiveSyncWhiteList.end() && (*it + QLatin1Char('/')).startsWith(pathSlash)) {
- // If the path is a prefix of something in the white list, we need to sync the contents
- return true;
- }
+ auto it = std::lower_bound(_selectiveSyncBlackList.begin(), _selectiveSyncBlackList.end(), pathSlash);
- // If the item before is a prefix of the path, we are also good
- if (it == _selectiveSyncWhiteList.begin()) {
+ if (it == _selectiveSyncBlackList.begin()) {
return false;
}
--it;
@@ -54,14 +45,14 @@ bool DiscoveryJob::isInWhiteList(const QString& path) const
int DiscoveryJob::isInWhiteListCallBack(void *data, const char *path)
{
- return static_cast<DiscoveryJob*>(data)->isInWhiteList(QString::fromUtf8(path));
+ return static_cast<DiscoveryJob*>(data)->isInBlackList(QString::fromUtf8(path));
}
void DiscoveryJob::start() {
- _selectiveSyncWhiteList.sort();
- _csync_ctx->checkWhiteListHook = isInWhiteListCallBack;
- _csync_ctx->checkWhiteListData = this;
+ _selectiveSyncBlackList.sort();
+ _csync_ctx->checkBlackListHook = isInWhiteListCallBack;
+ _csync_ctx->checkBlackListData = 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 2044b62..88b5581 100644
--- a/src/mirall/discoveryphase.h
+++ b/src/mirall/discoveryphase.h
@@ -35,7 +35,7 @@ class DiscoveryJob : public QObject {
* return true if the given path should be synced,
* false if the path should be ignored
*/
- bool isInWhiteList(const QString &path) const;
+ bool isInBlackList(const QString &path) const;
static int isInWhiteListCallBack(void *, const char *);
public:
@@ -48,7 +48,7 @@ public:
_log_userdata = csync_get_log_userdata();
}
- QStringList _selectiveSyncWhiteList;
+ QStringList _selectiveSyncBlackList;
Q_INVOKABLE void start();
signals:
void finished(int result);
diff --git a/src/mirall/folder.cpp b/src/mirall/folder.cpp
index b0efb5e..dd293b7 100644
--- a/src/mirall/folder.cpp
+++ b/src/mirall/folder.cpp
@@ -596,7 +596,7 @@ void Folder::startSync(const QStringList &pathList)
connect(_engine.data(), SIGNAL(jobCompleted(SyncFileItem)), this, SLOT(slotJobCompleted(SyncFileItem)));
setDirtyNetworkLimits();
- _engine->setSelectiveSyncWhiteList(selectiveSyncList());
+ _engine->setSelectiveSyncBlackList(selectiveSyncBlackList());
QMetaObject::invokeMethod(_engine.data(), "startSync", Qt::QueuedConnection);
diff --git a/src/mirall/folder.h b/src/mirall/folder.h
index 52304c8..5b84783 100644
--- a/src/mirall/folder.h
+++ b/src/mirall/folder.h
@@ -121,9 +121,9 @@ public:
SyncJournalDb *journalDb() { return &_journal; }
CSYNC *csyncContext() { return _csync_ctx; }
- QStringList selectiveSyncList() { return _selectiveSyncWhiteList; }
- void setSelectiveSyncList(const QStringList &whiteList)
- { _selectiveSyncWhiteList = whiteList; }
+ QStringList selectiveSyncBlackList() { return _selectiveSyncBlackList; }
+ void setSelectiveSyncBlackList(const QStringList &blackList)
+ { _selectiveSyncBlackList = blackList; }
signals:
@@ -192,7 +192,7 @@ private:
SyncResult _syncResult;
QScopedPointer<SyncEngine> _engine;
QStringList _errors;
- QStringList _selectiveSyncWhiteList;
+ QStringList _selectiveSyncBlackList;
bool _csyncError;
bool _csyncUnavail;
bool _wipeDb;
diff --git a/src/mirall/folderman.cpp b/src/mirall/folderman.cpp
index 554ea34..24ad667 100644
--- a/src/mirall/folderman.cpp
+++ b/src/mirall/folderman.cpp
@@ -312,7 +312,7 @@ Folder* FolderMan::setupFolderFromConfigFile(const QString &file) {
QString backend = settings.value(QLatin1String("backend")).toString();
QString targetPath = settings.value( QLatin1String("targetPath")).toString();
bool paused = settings.value( QLatin1String("paused"), false).toBool();
- QStringList whiteList = settings.value( QLatin1String("whiteList")).toStringList();
+ QStringList blackList = settings.value( QLatin1String("blackList")).toStringList();
// QString connection = settings.value( QLatin1String("connection") ).toString();
QString alias = unescapeAlias( escapedAlias );
@@ -328,7 +328,7 @@ Folder* FolderMan::setupFolderFromConfigFile(const QString &file) {
folder = new Folder( alias, path, targetPath, this );
folder->setConfigFile(cfgFile.absoluteFilePath());
- folder->setSelectiveSyncList(whiteList);
+ folder->setSelectiveSyncBlackList(blackList);
qDebug() << "Adding folder to Folder Map " << folder;
_folderMap[alias] = folder;
if (paused) {
diff --git a/src/mirall/selectivesyncdialog.cpp b/src/mirall/selectivesyncdialog.cpp
index ceeba0e..35cecd2 100644
--- a/src/mirall/selectivesyncdialog.cpp
+++ b/src/mirall/selectivesyncdialog.cpp
@@ -91,10 +91,10 @@ void SelectiveSyncDialog::recursiveInsert(QTreeWidgetItem* parent, QStringList p
} else if (parent->checkState(0) == Qt::Unchecked) {
item->setCheckState(0, Qt::Unchecked);
} else {
- item->setCheckState(0, Qt::Unchecked);
- foreach(const QString &str , _folder->selectiveSyncList()) {
+ item->setCheckState(0, Qt::Checked);
+ foreach(const QString &str , _folder->selectiveSyncBlackList()) {
if (str + "/" == path) {
- item->setCheckState(0, Qt::Checked);
+ item->setCheckState(0, Qt::Unchecked);
break;
} else if (str.startsWith(path)) {
item->setCheckState(0, Qt::PartiallyChecked);
@@ -123,7 +123,7 @@ void SelectiveSyncDialog::slotUpdateDirectories(const QStringList &list)
root->setText(0, _folder->alias());
root->setIcon(0, Theme::instance()->applicationIcon());
root->setData(0, Qt::UserRole, _folder->remotePath());
- if (_folder->selectiveSyncList().isEmpty() || _folder->selectiveSyncList().contains(QString())) {
+ if (_folder->selectiveSyncBlackList().isEmpty() || _folder->selectiveSyncBlackList().contains(QString())) {
root->setCheckState(0, Qt::Checked);
} else {
root->setCheckState(0, Qt::PartiallyChecked);
@@ -212,7 +212,7 @@ void SelectiveSyncDialog::slotItemChanged(QTreeWidgetItem *item, int col)
}
}
-QStringList SelectiveSyncDialog::createWhiteList(QTreeWidgetItem* root) const
+QStringList SelectiveSyncDialog::createBlackList(QTreeWidgetItem* root) const
{
if (!root) {
root = _treeView->topLevelItem(0);
@@ -220,9 +220,9 @@ QStringList SelectiveSyncDialog::createWhiteList(QTreeWidgetItem* root) const
if (!root) return {};
switch(root->checkState(0)) {
- case Qt::Checked:
- return { root->data(0, Qt::UserRole).toString() };
case Qt::Unchecked:
+ return { root->data(0, Qt::UserRole).toString() };
+ case Qt::Checked:
return {};
case Qt::PartiallyChecked:
break;
@@ -231,12 +231,12 @@ QStringList SelectiveSyncDialog::createWhiteList(QTreeWidgetItem* root) const
QStringList result;
if (root->childCount()) {
for (int i = 0; i < root->childCount(); ++i) {
- result += createWhiteList(root->child(i));
+ result += createBlackList(root->child(i));
}
} else {
// We did not load from the server so we re-use the one from the old white list
QString path = root->data(0, Qt::UserRole).toString();
- foreach (const QString & it, _folder->selectiveSyncList()) {
+ foreach (const QString & it, _folder->selectiveSyncBlackList()) {
if (it.startsWith(path))
result += it;
}
@@ -246,13 +246,13 @@ QStringList SelectiveSyncDialog::createWhiteList(QTreeWidgetItem* root) const
void SelectiveSyncDialog::accept()
{
- QStringList whiteList = createWhiteList();
- _folder->setSelectiveSyncList(whiteList);
+ QStringList blackList = createBlackList();
+ _folder->setSelectiveSyncBlackList(blackList);
// FIXME: Use MirallConfigFile
QSettings settings(_folder->configFile(), QSettings::IniFormat);
settings.beginGroup(FolderMan::escapeAlias(_folder->alias()));
- settings.setValue("whiteList", whiteList);
+ settings.setValue("blackList", blackList);
QDialog::accept();
}
diff --git a/src/mirall/selectivesyncdialog.h b/src/mirall/selectivesyncdialog.h
index a74a7aa..809f2c1 100644
--- a/src/mirall/selectivesyncdialog.h
+++ b/src/mirall/selectivesyncdialog.h
@@ -27,7 +27,7 @@ public:
explicit SelectiveSyncDialog(Folder *folder, QWidget* parent = 0, Qt::WindowFlags f = 0);
virtual void accept() Q_DECL_OVERRIDE;
- QStringList createWhiteList(QTreeWidgetItem* root = 0) const;
+ QStringList createBlackList(QTreeWidgetItem* root = 0) const;
private slots:
void refreshFolders();
diff --git a/src/mirall/syncengine.cpp b/src/mirall/syncengine.cpp
index a207349..5f2e278 100644
--- a/src/mirall/syncengine.cpp
+++ b/src/mirall/syncengine.cpp
@@ -533,7 +533,7 @@ void SyncEngine::startSync()
qDebug() << "#### Discovery start #################################################### >>";
DiscoveryJob *job = new DiscoveryJob(_csync_ctx);
- job->_selectiveSyncWhiteList = _selectiveSyncWhiteList;
+ job->_selectiveSyncBlackList = _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 71b4505..292ba35 100644
--- a/src/mirall/syncengine.h
+++ b/src/mirall/syncengine.h
@@ -59,7 +59,7 @@ public:
Utility::StopWatch &stopWatch() { return _stopWatch; }
- void setSelectiveSyncWhiteList(const QStringList &list)
+ void setSelectiveSyncBlackList(const QStringList &list)
{ _selectiveSyncWhiteList = list; }
signals:
--
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