2014-08-11 19:47:16 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Olivier Goffart <ogoffart@woboq.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "discoveryphase.h"
|
2014-08-11 20:41:42 +04:00
|
|
|
#include <csync_private.h>
|
2014-08-12 13:43:42 +04:00
|
|
|
#include <qdebug.h>
|
2014-08-11 20:41:42 +04:00
|
|
|
|
2014-08-15 14:29:10 +04:00
|
|
|
bool DiscoveryJob::isInBlackList(const QString& path) const
|
2014-08-11 20:41:42 +04:00
|
|
|
{
|
2014-08-15 14:29:10 +04:00
|
|
|
if (_selectiveSyncBlackList.isEmpty()) {
|
|
|
|
// If there is no black list, everything is allowed
|
|
|
|
return false;
|
2014-08-11 20:41:42 +04:00
|
|
|
}
|
|
|
|
|
2014-08-15 14:29:10 +04:00
|
|
|
// If one of the item in the black list is a prefix of the path, it means this path need not to
|
2014-08-11 20:41:42 +04:00
|
|
|
// be synced.
|
|
|
|
//
|
|
|
|
// We know the list is sorted (for it is done in DiscoveryJob::start)
|
2014-08-15 14:29:10 +04:00
|
|
|
// So we can do a binary search. If the path is a prefix if another item or right after in the lexical order.
|
2014-08-11 20:41:42 +04:00
|
|
|
|
2014-08-12 13:43:42 +04:00
|
|
|
QString pathSlash = path + QLatin1Char('/');
|
2014-08-11 20:41:42 +04:00
|
|
|
|
2014-08-15 14:29:10 +04:00
|
|
|
auto it = std::lower_bound(_selectiveSyncBlackList.begin(), _selectiveSyncBlackList.end(), pathSlash);
|
2014-08-11 20:41:42 +04:00
|
|
|
|
2014-08-15 14:29:10 +04:00
|
|
|
if (it == _selectiveSyncBlackList.begin()) {
|
2014-08-11 20:41:42 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
--it;
|
2014-08-12 13:43:42 +04:00
|
|
|
if (pathSlash.startsWith(*it + QLatin1Char('/'))) {
|
2014-08-11 20:41:42 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DiscoveryJob::isInWhiteListCallBack(void *data, const char *path)
|
|
|
|
{
|
2014-08-15 14:29:10 +04:00
|
|
|
return static_cast<DiscoveryJob*>(data)->isInBlackList(QString::fromUtf8(path));
|
2014-08-11 20:41:42 +04:00
|
|
|
}
|
|
|
|
|
2014-08-11 19:47:16 +04:00
|
|
|
|
|
|
|
void DiscoveryJob::start() {
|
2014-08-15 14:29:10 +04:00
|
|
|
_selectiveSyncBlackList.sort();
|
|
|
|
_csync_ctx->checkBlackListHook = isInWhiteListCallBack;
|
|
|
|
_csync_ctx->checkBlackListData = this;
|
2014-08-11 19:47:16 +04:00
|
|
|
csync_set_log_callback(_log_callback);
|
|
|
|
csync_set_log_level(_log_level);
|
|
|
|
csync_set_log_userdata(_log_userdata);
|
|
|
|
emit finished(csync_update(_csync_ctx));
|
|
|
|
deleteLater();
|
|
|
|
}
|