[Pkg-owncloud-commits] [owncloud-client] 75/470: Move the csync_context creation in SyncEngine
Sandro Knauß
hefee-guest at moszumanska.debian.org
Thu May 12 16:24:46 UTC 2016
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 b8227afcaaebf2c57a53de9af71aa325feb8cfa7
Author: Jocelyn Turcotte <jturcotte at woboq.com>
Date: Wed Feb 10 21:55:16 2016 +0100
Move the csync_context creation in SyncEngine
The creation doesn't need to be separated from the SyncEngine anymore.
This allows the SyncEngine to be created in fewer steps if we want to
use it in tests.
This moves most of the direct csync code from Folder into the SyncEngine.
The exclude file logic for the context has been wrapped using the
existing ExcludedFiles class as well.
---
csync/src/csync.c | 8 ---
csync/src/csync.h | 7 ---
csync/src/csync_exclude.c | 17 -----
csync/src/csync_exclude.h | 31 ---------
csync/tests/csync_tests/check_csync_exclude.c | 80 +++++++++++------------
src/cmd/cmd.cpp | 44 ++++---------
src/gui/folder.cpp | 91 ++++++---------------------
src/gui/folder.h | 4 --
src/libsync/excludedfiles.cpp | 22 ++++---
src/libsync/excludedfiles.h | 10 +--
src/libsync/syncengine.cpp | 35 +++++++++--
src/libsync/syncengine.h | 10 ++-
12 files changed, 127 insertions(+), 232 deletions(-)
diff --git a/csync/src/csync.c b/csync/src/csync.c
index 43865ac..dd38ffc 100644
--- a/csync/src/csync.c
+++ b/csync/src/csync.c
@@ -579,9 +579,6 @@ int csync_destroy(CSYNC *ctx) {
}
ctx->statedb.db = NULL;
- /* destroy exclude list */
- csync_exclude_destroy(ctx);
-
_csync_clean_ctx(ctx);
SAFE_FREE(ctx->local.uri);
@@ -605,11 +602,6 @@ int csync_add_exclude_list(CSYNC *ctx, const char *path) {
return csync_exclude_load(path, &ctx->excludes);
}
-void csync_clear_exclude_list(CSYNC *ctx)
-{
- csync_exclude_clear(ctx);
-}
-
void *csync_get_userdata(CSYNC *ctx) {
if (ctx == NULL) {
return NULL;
diff --git a/csync/src/csync.h b/csync/src/csync.h
index d00c573..c2448c0 100644
--- a/csync/src/csync.h
+++ b/csync/src/csync.h
@@ -378,13 +378,6 @@ int csync_destroy(CSYNC *ctx);
int csync_add_exclude_list(CSYNC *ctx, const char *path);
/**
- * @brief Removes all items imported from exclude lists.
- *
- * @param ctx The context to add the exclude list.
- */
-void csync_clear_exclude_list(CSYNC *ctx);
-
-/**
* @brief Get the userdata saved in the context.
*
* @param ctx The csync context.
diff --git a/csync/src/csync_exclude.c b/csync/src/csync_exclude.c
index 3754251..8753f27 100644
--- a/csync/src/csync_exclude.c
+++ b/csync/src/csync_exclude.c
@@ -117,23 +117,6 @@ out:
return rc;
}
-void csync_exclude_clear(CSYNC *ctx) {
- c_strlist_clear(ctx->excludes);
-}
-
-void csync_exclude_destroy(CSYNC *ctx) {
- c_strlist_destroy(ctx->excludes);
-}
-
-CSYNC_EXCLUDE_TYPE csync_excluded(CSYNC *ctx, const char *path, int filetype) {
-
- CSYNC_EXCLUDE_TYPE match = CSYNC_NOT_EXCLUDED;
-
- match = csync_excluded_no_ctx( ctx->excludes, path, filetype );
-
- return match;
-}
-
// See http://support.microsoft.com/kb/74496 and
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx
// Additionally, we ignore '$Recycle.Bin', see https://github.com/owncloud/client/issues/2955
diff --git a/csync/src/csync_exclude.h b/csync/src/csync_exclude.h
index 90acc4b..5a19a90 100644
--- a/csync/src/csync_exclude.h
+++ b/csync/src/csync_exclude.h
@@ -48,37 +48,6 @@ int _csync_exclude_add(c_strlist_t **inList, const char *string);
int csync_exclude_load(const char *fname, c_strlist_t **list);
/**
- * @brief Clear the exclude list in memory.
- *
- * @param ctx The synchronizer context.
- */
-void csync_exclude_clear(CSYNC *ctx);
-
-/**
- * @brief Destroy the exclude list in memory.
- *
- * @param ctx The synchronizer context.
- */
-void csync_exclude_destroy(CSYNC *ctx);
-
-/**
- * @brief Check if the given path should be excluded.
- *
- * This excludes also paths which can't be used without unix extensions.
- *
- * The exclude list is checked against the full path, each component of
- * the path and all leading directory strings, e.g.
- * '/foo/bar/file' checks ('/foo/bar/file', 'foo', 'bar', 'file',
- * '/foo/bar', '/foo').
- *
- * @param ctx The synchronizer context.
- * @param path The patch to check.
- *
- * @return 2 if excluded and needs cleanup, 1 if excluded, 0 if not.
- */
-CSYNC_EXCLUDE_TYPE csync_excluded(CSYNC *ctx, const char *path, int filetype);
-
-/**
* @brief Check if the given path should be excluded in a traversal situation.
*
* It does only part of the work that csync_excluded does because it's assumed
diff --git a/csync/tests/csync_tests/check_csync_exclude.c b/csync/tests/csync_tests/check_csync_exclude.c
index 419021c..f050809 100644
--- a/csync/tests/csync_tests/check_csync_exclude.c
+++ b/csync/tests/csync_tests/check_csync_exclude.c
@@ -100,84 +100,84 @@ static void check_csync_excluded(void **state)
CSYNC *csync = *state;
int rc;
- rc = csync_excluded(csync, "", CSYNC_FTW_TYPE_FILE);
+ rc = csync_excluded_no_ctx(csync->excludes, "", CSYNC_FTW_TYPE_FILE);
assert_int_equal(rc, CSYNC_NOT_EXCLUDED);
- rc = csync_excluded(csync, "/", CSYNC_FTW_TYPE_FILE);
+ rc = csync_excluded_no_ctx(csync->excludes, "/", CSYNC_FTW_TYPE_FILE);
assert_int_equal(rc, CSYNC_NOT_EXCLUDED);
- rc = csync_excluded(csync, "krawel_krawel", CSYNC_FTW_TYPE_FILE);
+ rc = csync_excluded_no_ctx(csync->excludes, "krawel_krawel", CSYNC_FTW_TYPE_FILE);
assert_int_equal(rc, CSYNC_NOT_EXCLUDED);
- rc = csync_excluded(csync, ".kde/share/config/kwin.eventsrc", CSYNC_FTW_TYPE_FILE);
+ rc = csync_excluded_no_ctx(csync->excludes, ".kde/share/config/kwin.eventsrc", CSYNC_FTW_TYPE_FILE);
assert_int_equal(rc, CSYNC_NOT_EXCLUDED);
- rc = csync_excluded(csync, ".htaccess/cache-maximegalon/cache1.txt", CSYNC_FTW_TYPE_FILE);
+ rc = csync_excluded_no_ctx(csync->excludes, ".htaccess/cache-maximegalon/cache1.txt", CSYNC_FTW_TYPE_FILE);
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
- rc = csync_excluded(csync, "mozilla/.htaccess", CSYNC_FTW_TYPE_DIR);
+ rc = csync_excluded_no_ctx(csync->excludes, "mozilla/.htaccess", CSYNC_FTW_TYPE_DIR);
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
/*
* Test for patterns in subdirs. '.beagle' is defined as a pattern and has
* to be found in top dir as well as in directories underneath.
*/
- rc = csync_excluded(csync, ".apdisk", CSYNC_FTW_TYPE_DIR);
+ rc = csync_excluded_no_ctx(csync->excludes, ".apdisk", CSYNC_FTW_TYPE_DIR);
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
- rc = csync_excluded(csync, "foo/.apdisk", CSYNC_FTW_TYPE_DIR);
+ rc = csync_excluded_no_ctx(csync->excludes, "foo/.apdisk", CSYNC_FTW_TYPE_DIR);
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
- rc = csync_excluded(csync, "foo/bar/.apdisk", CSYNC_FTW_TYPE_DIR);
+ rc = csync_excluded_no_ctx(csync->excludes, "foo/bar/.apdisk", CSYNC_FTW_TYPE_DIR);
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
- rc = csync_excluded(csync, ".java", CSYNC_FTW_TYPE_FILE);
+ rc = csync_excluded_no_ctx(csync->excludes, ".java", CSYNC_FTW_TYPE_FILE);
assert_int_equal(rc, CSYNC_NOT_EXCLUDED);
/* Files in the ignored dir .java will also be ignored. */
- rc = csync_excluded(csync, ".apdisk/totally_amazing.jar", CSYNC_FTW_TYPE_FILE);
+ rc = csync_excluded_no_ctx(csync->excludes, ".apdisk/totally_amazing.jar", CSYNC_FTW_TYPE_FILE);
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
/* and also in subdirs */
- rc = csync_excluded(csync, "projects/.apdisk/totally_amazing.jar", CSYNC_FTW_TYPE_FILE);
+ rc = csync_excluded_no_ctx(csync->excludes, "projects/.apdisk/totally_amazing.jar", CSYNC_FTW_TYPE_FILE);
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
/* csync-journal is ignored in general silently. */
- rc = csync_excluded(csync, ".csync_journal.db", CSYNC_FTW_TYPE_FILE);
+ rc = csync_excluded_no_ctx(csync->excludes, ".csync_journal.db", CSYNC_FTW_TYPE_FILE);
assert_int_equal(rc, CSYNC_FILE_SILENTLY_EXCLUDED);
- rc = csync_excluded(csync, ".csync_journal.db.ctmp", CSYNC_FTW_TYPE_FILE);
+ rc = csync_excluded_no_ctx(csync->excludes, ".csync_journal.db.ctmp", CSYNC_FTW_TYPE_FILE);
assert_int_equal(rc, CSYNC_FILE_SILENTLY_EXCLUDED);
- rc = csync_excluded(csync, "subdir/.csync_journal.db", CSYNC_FTW_TYPE_FILE);
+ rc = csync_excluded_no_ctx(csync->excludes, "subdir/.csync_journal.db", CSYNC_FTW_TYPE_FILE);
assert_int_equal(rc, CSYNC_FILE_SILENTLY_EXCLUDED);
/* pattern ]*.directory - ignore and remove */
- rc = csync_excluded(csync, "my.~directory", CSYNC_FTW_TYPE_FILE);
+ rc = csync_excluded_no_ctx(csync->excludes, "my.~directory", CSYNC_FTW_TYPE_FILE);
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_AND_REMOVE);
- rc = csync_excluded(csync, "/a_folder/my.~directory", CSYNC_FTW_TYPE_FILE);
+ rc = csync_excluded_no_ctx(csync->excludes, "/a_folder/my.~directory", CSYNC_FTW_TYPE_FILE);
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_AND_REMOVE);
/* Not excluded because the pattern .netscape/cache requires directory. */
- rc = csync_excluded(csync, ".netscape/cache", CSYNC_FTW_TYPE_FILE);
+ rc = csync_excluded_no_ctx(csync->excludes, ".netscape/cache", CSYNC_FTW_TYPE_FILE);
assert_int_equal(rc, CSYNC_NOT_EXCLUDED);
/* Not excluded */
- rc = csync_excluded(csync, "unicode/中文.hé", CSYNC_FTW_TYPE_FILE);
+ rc = csync_excluded_no_ctx(csync->excludes, "unicode/中文.hé", CSYNC_FTW_TYPE_FILE);
assert_int_equal(rc, CSYNC_NOT_EXCLUDED);
/* excluded */
- rc = csync_excluded(csync, "unicode/пятницы.txt", CSYNC_FTW_TYPE_FILE);
+ rc = csync_excluded_no_ctx(csync->excludes, "unicode/пятницы.txt", CSYNC_FTW_TYPE_FILE);
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
- rc = csync_excluded(csync, "unicode/中文.💩", CSYNC_FTW_TYPE_FILE);
+ rc = csync_excluded_no_ctx(csync->excludes, "unicode/中文.💩", CSYNC_FTW_TYPE_FILE);
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
/* path wildcards */
- rc = csync_excluded(csync, "foobar/my_manuscript.out", CSYNC_FTW_TYPE_FILE);
+ rc = csync_excluded_no_ctx(csync->excludes, "foobar/my_manuscript.out", CSYNC_FTW_TYPE_FILE);
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
- rc = csync_excluded(csync, "latex_tmp/my_manuscript.run.xml", CSYNC_FTW_TYPE_FILE);
+ rc = csync_excluded_no_ctx(csync->excludes, "latex_tmp/my_manuscript.run.xml", CSYNC_FTW_TYPE_FILE);
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
- rc = csync_excluded(csync, "word_tmp/my_manuscript.run.xml", CSYNC_FTW_TYPE_FILE);
+ rc = csync_excluded_no_ctx(csync->excludes, "word_tmp/my_manuscript.run.xml", CSYNC_FTW_TYPE_FILE);
assert_int_equal(rc, CSYNC_NOT_EXCLUDED);
- rc = csync_excluded(csync, "latex/my_manuscript.tex.tmp", CSYNC_FTW_TYPE_FILE);
+ rc = csync_excluded_no_ctx(csync->excludes, "latex/my_manuscript.tex.tmp", CSYNC_FTW_TYPE_FILE);
assert_int_equal(rc, CSYNC_NOT_EXCLUDED);
- rc = csync_excluded(csync, "latex/songbook/my_manuscript.tex.tmp", CSYNC_FTW_TYPE_FILE);
+ rc = csync_excluded_no_ctx(csync->excludes, "latex/songbook/my_manuscript.tex.tmp", CSYNC_FTW_TYPE_FILE);
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
}
@@ -239,45 +239,45 @@ static void check_csync_pathes(void **state)
_csync_exclude_add( &(csync->excludes), "/exclude" );
/* Check toplevel dir, the pattern only works for toplevel dir. */
- rc = csync_excluded(csync, "/exclude", CSYNC_FTW_TYPE_DIR);
+ rc = csync_excluded_no_ctx(csync->excludes, "/exclude", CSYNC_FTW_TYPE_DIR);
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
- rc = csync_excluded(csync, "/foo/exclude", CSYNC_FTW_TYPE_DIR);
+ rc = csync_excluded_no_ctx(csync->excludes, "/foo/exclude", CSYNC_FTW_TYPE_DIR);
assert_int_equal(rc, CSYNC_NOT_EXCLUDED);
/* check for a file called exclude. Must still work */
- rc = csync_excluded(csync, "/exclude", CSYNC_FTW_TYPE_FILE);
+ rc = csync_excluded_no_ctx(csync->excludes, "/exclude", CSYNC_FTW_TYPE_FILE);
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
- rc = csync_excluded(csync, "/foo/exclude", CSYNC_FTW_TYPE_FILE);
+ rc = csync_excluded_no_ctx(csync->excludes, "/foo/exclude", CSYNC_FTW_TYPE_FILE);
assert_int_equal(rc, CSYNC_NOT_EXCLUDED);
/* Add an exclude for directories only: excl/ */
_csync_exclude_add( &(csync->excludes), "excl/" );
- rc = csync_excluded(csync, "/excl", CSYNC_FTW_TYPE_DIR);
+ rc = csync_excluded_no_ctx(csync->excludes, "/excl", CSYNC_FTW_TYPE_DIR);
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
- rc = csync_excluded(csync, "meep/excl", CSYNC_FTW_TYPE_DIR);
+ rc = csync_excluded_no_ctx(csync->excludes, "meep/excl", CSYNC_FTW_TYPE_DIR);
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
- rc = csync_excluded(csync, "meep/excl/file", CSYNC_FTW_TYPE_FILE);
+ rc = csync_excluded_no_ctx(csync->excludes, "meep/excl/file", CSYNC_FTW_TYPE_FILE);
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
- rc = csync_excluded(csync, "/excl", CSYNC_FTW_TYPE_FILE);
+ rc = csync_excluded_no_ctx(csync->excludes, "/excl", CSYNC_FTW_TYPE_FILE);
assert_int_equal(rc, CSYNC_NOT_EXCLUDED);
_csync_exclude_add(&csync->excludes, "/excludepath/withsubdir");
- rc = csync_excluded(csync, "/excludepath/withsubdir", CSYNC_FTW_TYPE_DIR);
+ rc = csync_excluded_no_ctx(csync->excludes, "/excludepath/withsubdir", CSYNC_FTW_TYPE_DIR);
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
- rc = csync_excluded(csync, "/excludepath/withsubdir", CSYNC_FTW_TYPE_FILE);
+ rc = csync_excluded_no_ctx(csync->excludes, "/excludepath/withsubdir", CSYNC_FTW_TYPE_FILE);
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
- rc = csync_excluded(csync, "/excludepath/withsubdir2", CSYNC_FTW_TYPE_DIR);
+ rc = csync_excluded_no_ctx(csync->excludes, "/excludepath/withsubdir2", CSYNC_FTW_TYPE_DIR);
assert_int_equal(rc, CSYNC_NOT_EXCLUDED);
- rc = csync_excluded(csync, "/excludepath/withsubdir/foo", CSYNC_FTW_TYPE_DIR);
+ rc = csync_excluded_no_ctx(csync->excludes, "/excludepath/withsubdir/foo", CSYNC_FTW_TYPE_DIR);
assert_int_equal(rc, CSYNC_FILE_EXCLUDE_LIST);
}
@@ -312,8 +312,8 @@ static void check_csync_excluded_performance(void **state)
gettimeofday(&before, 0);
for (int i = 0; i < N; ++i) {
- totalRc += csync_excluded(csync, "/this/is/quite/a/long/path/with/many/components", CSYNC_FTW_TYPE_DIR);
- totalRc += csync_excluded(csync, "/1/2/3/4/5/6/7/8/9/10/11/12/13/14/15/16/17/18/19/20/21/22/23/24/25/26/27/29", CSYNC_FTW_TYPE_FILE);
+ totalRc += csync_excluded_no_ctx(csync->excludes, "/this/is/quite/a/long/path/with/many/components", CSYNC_FTW_TYPE_DIR);
+ totalRc += csync_excluded_no_ctx(csync->excludes, "/1/2/3/4/5/6/7/8/9/10/11/12/13/14/15/16/17/18/19/20/21/22/23/24/25/26/27/29", CSYNC_FTW_TYPE_FILE);
}
assert_int_equal(totalRc, CSYNC_NOT_EXCLUDED); // mainly to avoid optimization
diff --git a/src/cmd/cmd.cpp b/src/cmd/cmd.cpp
index c426e38..5516784 100644
--- a/src/cmd/cmd.cpp
+++ b/src/cmd/cmd.cpp
@@ -385,19 +385,10 @@ int main(int argc, char **argv) {
int restartCount = 0;
restart_sync:
- CSYNC *_csync_ctx;
-
- csync_create( &_csync_ctx, options.source_dir.toUtf8(), remUrl.constData());
-
csync_set_log_level(options.silent ? 1 : 11);
opts = &options;
- csync_init( _csync_ctx );
-
- // ignore hidden files or not
- _csync_ctx->ignore_hidden_files = options.ignoreHiddenFiles;
-
if( !options.proxy.isNull() ) {
QString host;
int port = 0;
@@ -424,18 +415,6 @@ restart_sync:
}
}
- // Exclude lists
- QString systemExcludeListFn = ConfigFile::excludeFileFromSystem();
- int loadedSystemExcludeList = false;
- if (!systemExcludeListFn.isEmpty()) {
- loadedSystemExcludeList = csync_add_exclude_list(_csync_ctx, systemExcludeListFn.toLocal8Bit());
- }
-
- int loadedUserExcludeList = false;
- if (!options.exclude.isEmpty()) {
- loadedUserExcludeList = csync_add_exclude_list(_csync_ctx, options.exclude.toLocal8Bit());
- }
-
QStringList selectiveSyncList;
if (!options.unsyncedfolders.isEmpty()) {
QFile f(options.unsyncedfolders);
@@ -453,30 +432,33 @@ restart_sync:
}
}
-
- if (loadedSystemExcludeList != 0 && loadedUserExcludeList != 0) {
- // Always make sure at least one list has been loaded
- qFatal("Cannot load system exclude list or list supplied via --exclude");
- return EXIT_FAILURE;
- }
-
Cmd cmd;
SyncJournalDb db(options.source_dir);
if (!selectiveSyncList.empty()) {
selectiveSyncFixup(&db, selectiveSyncList);
}
- SyncEngine engine(account, _csync_ctx, options.source_dir, QUrl(options.target_url).path(), folder, &db);
+ SyncEngine engine(account, options.source_dir, QUrl(options.target_url), folder, &db);
+ engine.setIgnoreHiddenFiles(options.ignoreHiddenFiles);
QObject::connect(&engine, SIGNAL(finished(bool)), &app, SLOT(quit()));
QObject::connect(&engine, SIGNAL(transmissionProgress(ProgressInfo)), &cmd, SLOT(transmissionProgressSlot()));
+// FIXME: Test (maybe even auto)
+ // Exclude lists
+ engine.excludedFiles().addExcludeFilePath(ConfigFile::excludeFileFromSystem());
+ if( QFile::exists(options.exclude) )
+ engine.excludedFiles().addExcludeFilePath(options.exclude);
+ if (!engine.excludedFiles().reloadExcludes()) {
+ // Always make sure at least one list has been loaded
+ qFatal("Cannot load system exclude list or list supplied via --exclude");
+ return EXIT_FAILURE;
+ }
+
// Have to be done async, else, an error before exec() does not terminate the event loop.
QMetaObject::invokeMethod(&engine, "startSync", Qt::QueuedConnection);
app.exec();
- csync_destroy(_csync_ctx);
-
if (engine.isAnotherSyncNeeded()) {
if (restartCount < options.restartTimes) {
restartCount++;
diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp
index 88904f2..8f9744d 100644
--- a/src/gui/folder.cpp
+++ b/src/gui/folder.cpp
@@ -46,15 +46,6 @@
namespace OCC {
-static void csyncLogCatcher(int /*verbosity*/,
- const char */*function*/,
- const char *buffer,
- void */*userdata*/)
-{
- Logger::instance()->csyncLog( QString::fromUtf8(buffer) );
-}
-
-
Folder::Folder(const FolderDefinition& definition,
QObject* parent)
: QObject(parent)
@@ -69,7 +60,6 @@ Folder::Folder(const FolderDefinition& definition,
, _consecutiveFailingSyncs(0)
, _consecutiveFollowUpSyncs(0)
, _journal(definition.localPath)
- , _csync_ctx(0)
{
qsrand(QTime::currentTime().msec());
_timeSinceLastSyncStart.start();
@@ -87,41 +77,12 @@ Folder::Folder(const FolderDefinition& definition,
_syncResult.setFolder(_definition.alias);
}
-bool Folder::init()
-{
- // We need to reconstruct the url because the path needs to be fully decoded, as csync will re-encode the path:
- // Remember that csync will just append the filename to the path and pass it to the vio plugin.
- // csync_owncloud will then re-encode everything.
-#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
- QUrl url = remoteUrl();
- QString url_string = url.scheme() + QLatin1String("://") + url.authority(QUrl::EncodeDelimiters) + url.path(QUrl::FullyDecoded);
-#else
- // Qt4 was broken anyway as it did not encode the '#' as it should have done (it was actually a problem when parsing the path from QUrl::setPath
- QString url_string = remoteUrl().toString();
-#endif
- url_string = Utility::toCSyncScheme(url_string);
-
- QString localpath = path();
-
- csync_create( &_csync_ctx, localpath.toUtf8().data(), url_string.toUtf8().data() );
- csync_init( _csync_ctx );
-
- csync_set_log_callback( csyncLogCatcher );
- csync_set_log_level( Logger::instance()->isNoop() ? 0 : 11 );
-
- Q_ASSERT( _accountState );
-
- return _csync_ctx;
-}
-
Folder::~Folder()
{
if( _engine ) {
_engine->abort();
_engine.reset(0);
}
- // Destroy csync here.
- csync_destroy(_csync_ctx);
}
void Folder::setAccountState( AccountState *account )
@@ -816,25 +777,19 @@ void Folder::wipe()
bool Folder::setIgnoredFiles()
{
- bool ok = false;
-
- ConfigFile cfgFile;
- csync_clear_exclude_list( _csync_ctx );
- QString excludeList = cfgFile.excludeFile( ConfigFile::SystemScope );
- if( !excludeList.isEmpty() ) {
- qDebug() << "==== added system ignore list to csync:" << excludeList.toUtf8();
- if (csync_add_exclude_list( _csync_ctx, excludeList.toUtf8() ) == 0) {
- ok = true;
- }
+ ConfigFile cfg;
+ QString systemList = cfg.excludeFile(ConfigFile::SystemScope);
+ if( QFile::exists(systemList) ) {
+ qDebug() << "==== adding system ignore list to csync:" << systemList;
+ _engine->excludedFiles().addExcludeFilePath(systemList);
}
- excludeList = cfgFile.excludeFile( ConfigFile::UserScope );
- if( !excludeList.isEmpty() ) {
- qDebug() << "==== added user defined ignore list to csync:" << excludeList.toUtf8();
- csync_add_exclude_list( _csync_ctx, excludeList.toUtf8() );
- // reading the user exclude file is optional
+ QString userList = cfg.excludeFile(ConfigFile::UserScope);
+ if( QFile::exists(userList) ) {
+ qDebug() << "==== adding user defined ignore list to csync:" << userList;
+ _engine->excludedFiles().addExcludeFilePath(userList);
}
- return ok;
+ return _engine->excludedFiles().reloadExcludes();
}
void Folder::setProxyDirty(bool value)
@@ -855,20 +810,9 @@ void Folder::startSync(const QStringList &pathList)
}
Q_UNUSED(pathList)
- if (!_csync_ctx) {
- // no _csync_ctx yet, initialize it.
- init();
-
- if (!_csync_ctx) {
- qDebug() << Q_FUNC_INFO << "init failed.";
- // the error should already be set
- QMetaObject::invokeMethod(this, "slotSyncFinished", Qt::QueuedConnection, Q_ARG(bool, false));
- return;
- }
- } else if (proxyDirty()) {
+ if (proxyDirty()) {
setProxyDirty(false);
}
- csync_set_log_level( Logger::instance()->isNoop() ? 0 : 11 );
if (isBusy()) {
qCritical() << "* ERROR csync is still running and new sync requested.";
@@ -887,18 +831,19 @@ void Folder::startSync(const QStringList &pathList)
qDebug() << "*** Start syncing " << remoteUrl().toString() << " - client version"
<< qPrintable(Theme::instance()->version());
- if (! setIgnoredFiles())
+ // pass the setting if hidden files are to be ignored, will be read in csync_update
+ _engine->setIgnoreHiddenFiles(_definition.ignoreHiddenFiles);
+ // _csync_ctx->ignore_hidden_files = _definition.ignoreHiddenFiles;
+
+ _engine.reset(new SyncEngine( _accountState->account(), path(), remoteUrl(), remotePath(), &_journal));
+
+ if (!setIgnoredFiles())
{
slotSyncError(tr("Could not read system exclude file"));
QMetaObject::invokeMethod(this, "slotSyncFinished", Qt::QueuedConnection, Q_ARG(bool, false));
return;
}
- // pass the setting if hidden files are to be ignored, will be read in csync_update
- _csync_ctx->ignore_hidden_files = _definition.ignoreHiddenFiles;
-
- _engine.reset(new SyncEngine( _accountState->account(), _csync_ctx, path(), remoteUrl().path(), remotePath(), &_journal));
-
qRegisterMetaType<SyncFileItemVector>("SyncFileItemVector");
qRegisterMetaType<SyncFileItem::Direction>("SyncFileItem::Direction");
diff --git a/src/gui/folder.h b/src/gui/folder.h
index b450e89..ebc46a5 100644
--- a/src/gui/folder.h
+++ b/src/gui/folder.h
@@ -273,8 +273,6 @@ private slots:
void slotNewBigFolderDiscovered(const QString &);
private:
- bool init();
-
bool setIgnoredFiles();
void bubbleUpSyncResult();
@@ -321,8 +319,6 @@ private:
SyncJournalDb _journal;
ClientProxy _clientProxy;
-
- CSYNC *_csync_ctx;
};
}
diff --git a/src/libsync/excludedfiles.cpp b/src/libsync/excludedfiles.cpp
index b71d538..4f84fc0 100644
--- a/src/libsync/excludedfiles.cpp
+++ b/src/libsync/excludedfiles.cpp
@@ -25,19 +25,20 @@ extern "C" {
using namespace OCC;
-ExcludedFiles::ExcludedFiles()
- : _excludes(NULL)
+ExcludedFiles::ExcludedFiles(c_strlist_t** excludesPtr)
+ : _excludesPtr(excludesPtr)
{
}
ExcludedFiles::~ExcludedFiles()
{
- c_strlist_destroy(_excludes);
+ c_strlist_destroy(*_excludesPtr);
}
ExcludedFiles& ExcludedFiles::instance()
{
- static ExcludedFiles inst;
+ static c_strlist_t* globalExcludes;
+ static ExcludedFiles inst(&globalExcludes);
return inst;
}
@@ -47,15 +48,18 @@ void ExcludedFiles::addExcludeFilePath(const QString& path)
_excludeFiles.append(path);
}
-void ExcludedFiles::reloadExcludes()
+bool ExcludedFiles::reloadExcludes()
{
QWriteLocker locker(&_mutex);
- c_strlist_destroy(_excludes);
- _excludes = NULL;
+ c_strlist_destroy(*_excludesPtr);
+ *_excludesPtr = NULL;
+ bool success = true;
foreach (const QString& file, _excludeFiles) {
- csync_exclude_load(file.toUtf8(), &_excludes);
+ if (csync_exclude_load(file.toUtf8(), _excludesPtr) < 0)
+ success = false;
}
+ return success;
}
CSYNC_EXCLUDE_TYPE ExcludedFiles::isExcluded(
@@ -76,5 +80,5 @@ CSYNC_EXCLUDE_TYPE ExcludedFiles::isExcluded(
type = CSYNC_FTW_TYPE_DIR;
}
QReadLocker lock(&_mutex);
- return csync_excluded_no_ctx(_excludes, relativePath.toUtf8(), type);
+ return csync_excluded_no_ctx(*_excludesPtr, relativePath.toUtf8(), type);
}
diff --git a/src/libsync/excludedfiles.h b/src/libsync/excludedfiles.h
index 7a4c7e2..1146042 100644
--- a/src/libsync/excludedfiles.h
+++ b/src/libsync/excludedfiles.h
@@ -36,6 +36,9 @@ class OWNCLOUDSYNC_EXPORT ExcludedFiles : public QObject
public:
static ExcludedFiles & instance();
+ ExcludedFiles(c_strlist_t** excludesPtr);
+ ~ExcludedFiles();
+
/**
* Adds a new path to a file containing exclude patterns.
*
@@ -60,13 +63,10 @@ public slots:
/**
* Reloads the exclude patterns from the registered paths.
*/
- void reloadExcludes();
+ bool reloadExcludes();
private:
- ExcludedFiles();
- ~ExcludedFiles();
-
- c_strlist_t* _excludes;
+ c_strlist_t** _excludesPtr;
QStringList _excludeFiles;
mutable QReadWriteLock _mutex;
};
diff --git a/src/libsync/syncengine.cpp b/src/libsync/syncengine.cpp
index ac3b3ea..a5763e0 100644
--- a/src/libsync/syncengine.cpp
+++ b/src/libsync/syncengine.cpp
@@ -15,6 +15,7 @@
#include "syncengine.h"
#include "account.h"
+#include "logger.h"
#include "owncloudpropagator.h"
#include "syncjournaldb.h"
#include "syncjournalfilerecord.h"
@@ -56,10 +57,17 @@ bool SyncEngine::_syncRunning = false;
qint64 SyncEngine::minimumFileAgeForUpload = 2000;
-SyncEngine::SyncEngine(AccountPtr account, CSYNC *ctx, const QString& localPath,
- const QString& remoteURL, const QString& remotePath, OCC::SyncJournalDb* journal)
+static void csyncLogCatcher(int /*verbosity*/,
+ const char */*function*/,
+ const char *buffer,
+ void */*userdata*/)
+{
+ Logger::instance()->csyncLog( QString::fromUtf8(buffer) );
+}
+
+SyncEngine::SyncEngine(AccountPtr account, const QString& localPath,
+ const QUrl& remoteURL, const QString& remotePath, OCC::SyncJournalDb* journal)
: _account(account)
- , _csync_ctx(ctx)
, _needsUpdate(false)
, _localPath(localPath)
, _remoteUrl(remoteURL)
@@ -79,12 +87,31 @@ SyncEngine::SyncEngine(AccountPtr account, CSYNC *ctx, const QString& localPath,
qRegisterMetaType<SyncFileItem>("SyncFileItem");
qRegisterMetaType<SyncFileItem::Status>("SyncFileItem::Status");
+ // We need to reconstruct the url because the path needs to be fully decoded, as csync will re-encode the path:
+ // Remember that csync will just append the filename to the path and pass it to the vio plugin.
+ // csync_owncloud will then re-encode everything.
+#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
+ QString url_string = _remoteUrl.scheme() + QLatin1String("://") + _remoteUrl.authority(QUrl::EncodeDelimiters) + _remoteUrl.path(QUrl::FullyDecoded);
+#else
+ // Qt4 was broken anyway as it did not encode the '#' as it should have done (it was actually a problem when parsing the path from QUrl::setPath
+ QString url_string = _remoteUrl.toString();
+#endif
+ url_string = Utility::toCSyncScheme(url_string);
+
+ csync_set_log_callback( csyncLogCatcher );
+ csync_set_log_level( Logger::instance()->isNoop() ? 0 : 11 );
+
+ csync_create(&_csync_ctx, localPath.toUtf8().data(), url_string.toUtf8().data());
+ csync_init(_csync_ctx);
+ _excludedFiles.reset(new ExcludedFiles(&_csync_ctx->excludes));
+
_thread.setObjectName("SyncEngine_Thread");
_thread.start();
}
SyncEngine::~SyncEngine()
{
+ csync_destroy(_csync_ctx);
_thread.quit();
_thread.wait();
}
@@ -889,7 +916,7 @@ void SyncEngine::slotDiscoveryJobFinished(int discoveryResult)
_journal->commit("post treewalk");
_propagator = QSharedPointer<OwncloudPropagator>(
- new OwncloudPropagator (_account, _localPath, _remoteUrl, _remotePath, _journal));
+ new OwncloudPropagator (_account, _localPath, _remoteUrl.path(), _remotePath, _journal));
connect(_propagator.data(), SIGNAL(itemCompleted(const SyncFileItem &, const PropagatorJob &)),
this, SLOT(slotItemCompleted(const SyncFileItem &, const PropagatorJob &)));
connect(_propagator.data(), SIGNAL(progress(const SyncFileItem &,quint64)),
diff --git a/src/libsync/syncengine.h b/src/libsync/syncengine.h
index 7e29309..7d24e89 100644
--- a/src/libsync/syncengine.h
+++ b/src/libsync/syncengine.h
@@ -31,6 +31,7 @@
// when do we go away with this private/public separation?
#include <csync_private.h>
+#include "excludedfiles.h"
#include "syncfileitem.h"
#include "progressdispatcher.h"
#include "utility.h"
@@ -56,8 +57,8 @@ class OWNCLOUDSYNC_EXPORT SyncEngine : public QObject
{
Q_OBJECT
public:
- SyncEngine(AccountPtr account, CSYNC *, const QString &localPath,
- const QString &remoteURL, const QString &remotePath, SyncJournalDb *journal);
+ SyncEngine(AccountPtr account, const QString &localPath,
+ const QUrl &remoteURL, const QString &remotePath, SyncJournalDb *journal);
~SyncEngine();
static QString csyncErrorToString( CSYNC_STATUS);
@@ -72,7 +73,9 @@ public:
* -1 means infinite
*/
void setNewBigFolderSizeLimit(qint64 limit) { _newBigFolderSizeLimit = limit; }
+ void setIgnoreHiddenFiles(bool ignore) { _csync_ctx->ignore_hidden_files = ignore; }
+ ExcludedFiles &excludedFiles() { return *_excludedFiles; }
Utility::StopWatch &stopWatch() { return _stopWatch; }
/* Return true if we detected that another sync is needed to complete the sync */
@@ -178,7 +181,7 @@ private:
CSYNC *_csync_ctx;
bool _needsUpdate;
QString _localPath;
- QString _remoteUrl;
+ QUrl _remoteUrl;
QString _remotePath;
QString _remoteRootEtag;
SyncJournalDb *_journal;
@@ -204,6 +207,7 @@ private:
QScopedPointer<ProgressInfo> _progressInfo;
+ QScopedPointer<ExcludedFiles> _excludedFiles;
Utility::StopWatch _stopWatch;
// maps the origin and the target of the folders that have been renamed
--
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