зеркало из https://github.com/nextcloud/desktop.git
Merge pull request #4513 from owncloud/csyncContextToSyncEngine
Move the csync_context creation in SyncEngine
This commit is contained in:
Коммит
54612455e6
|
@ -25,6 +25,7 @@
|
|||
#define _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
@ -89,14 +90,11 @@ static int _data_cmp(const void *key, const void *data) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int csync_create(CSYNC **csync, const char *local, const char *remote) {
|
||||
void csync_create(CSYNC **csync, const char *local, const char *remote) {
|
||||
CSYNC *ctx;
|
||||
size_t len = 0;
|
||||
|
||||
ctx = c_malloc(sizeof(CSYNC));
|
||||
if (ctx == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ctx->status_code = CSYNC_STATUS_OK;
|
||||
|
||||
|
@ -121,46 +119,21 @@ int csync_create(CSYNC **csync, const char *local, const char *remote) {
|
|||
ctx->ignore_hidden_files = true;
|
||||
|
||||
*csync = ctx;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int csync_init(CSYNC *ctx) {
|
||||
int rc;
|
||||
|
||||
if (ctx == NULL) {
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
|
||||
ctx->status_code = CSYNC_STATUS_OK;
|
||||
|
||||
void csync_init(CSYNC *ctx) {
|
||||
assert(ctx);
|
||||
/* Do not initialize twice */
|
||||
if (ctx->status & CSYNC_STATUS_INIT) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* check for uri */
|
||||
if (csync_fnmatch("owncloud://*", ctx->remote.uri, 0) == 0 && csync_fnmatch("ownclouds://*", ctx->remote.uri, 0) == 0) {
|
||||
ctx->status_code = CSYNC_STATUS_NO_MODULE;
|
||||
rc = -1;
|
||||
goto out;
|
||||
}
|
||||
assert(!(ctx->status & CSYNC_STATUS_INIT));
|
||||
ctx->status_code = CSYNC_STATUS_OK;
|
||||
|
||||
ctx->local.type = LOCAL_REPLICA;
|
||||
|
||||
ctx->remote.type = REMOTE_REPLICA;
|
||||
|
||||
if (c_rbtree_create(&ctx->local.tree, _key_cmp, _data_cmp) < 0) {
|
||||
ctx->status_code = CSYNC_STATUS_TREE_ERROR;
|
||||
rc = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (c_rbtree_create(&ctx->remote.tree, _key_cmp, _data_cmp) < 0) {
|
||||
ctx->status_code = CSYNC_STATUS_TREE_ERROR;
|
||||
rc = -1;
|
||||
goto out;
|
||||
}
|
||||
c_rbtree_create(&ctx->local.tree, _key_cmp, _data_cmp);
|
||||
c_rbtree_create(&ctx->remote.tree, _key_cmp, _data_cmp);
|
||||
|
||||
ctx->remote.root_perms = 0;
|
||||
|
||||
|
@ -168,11 +141,6 @@ int csync_init(CSYNC *ctx) {
|
|||
|
||||
/* initialize random generator */
|
||||
srand(time(NULL));
|
||||
|
||||
rc = 0;
|
||||
|
||||
out:
|
||||
return rc;
|
||||
}
|
||||
|
||||
int csync_update(CSYNC *ctx) {
|
||||
|
@ -584,25 +552,14 @@ int csync_commit(CSYNC *ctx) {
|
|||
|
||||
|
||||
/* Create new trees */
|
||||
rc = c_rbtree_create(&ctx->local.tree, _key_cmp, _data_cmp);
|
||||
if (rc < 0) {
|
||||
ctx->status_code = CSYNC_STATUS_TREE_ERROR;
|
||||
goto out;
|
||||
}
|
||||
|
||||
rc = c_rbtree_create(&ctx->remote.tree, _key_cmp, _data_cmp);
|
||||
if (rc < 0) {
|
||||
ctx->status_code = CSYNC_STATUS_TREE_ERROR;
|
||||
goto out;
|
||||
}
|
||||
c_rbtree_create(&ctx->local.tree, _key_cmp, _data_cmp);
|
||||
c_rbtree_create(&ctx->remote.tree, _key_cmp, _data_cmp);
|
||||
|
||||
|
||||
ctx->status = CSYNC_STATUS_INIT;
|
||||
SAFE_FREE(ctx->error_string);
|
||||
|
||||
rc = 0;
|
||||
|
||||
out:
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
@ -622,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);
|
||||
|
@ -640,19 +594,6 @@ int csync_destroy(CSYNC *ctx) {
|
|||
return rc;
|
||||
}
|
||||
|
||||
int csync_add_exclude_list(CSYNC *ctx, const char *path) {
|
||||
if (ctx == NULL || path == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
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;
|
||||
|
|
|
@ -316,10 +316,8 @@ typedef const char* (*csync_checksum_hook) (
|
|||
* @brief Allocate a csync context.
|
||||
*
|
||||
* @param csync The context variable to allocate.
|
||||
*
|
||||
* @return 0 on success, less than 0 if an error occurred.
|
||||
*/
|
||||
int csync_create(CSYNC **csync, const char *local, const char *remote);
|
||||
void csync_create(CSYNC **csync, const char *local, const char *remote);
|
||||
|
||||
/**
|
||||
* @brief Initialize the file synchronizer.
|
||||
|
@ -327,10 +325,8 @@ int csync_create(CSYNC **csync, const char *local, const char *remote);
|
|||
* This function loads the configuration
|
||||
*
|
||||
* @param ctx The context to initialize.
|
||||
*
|
||||
* @return 0 on success, less than 0 if an error occurred.
|
||||
*/
|
||||
int csync_init(CSYNC *ctx);
|
||||
void csync_init(CSYNC *ctx);
|
||||
|
||||
/**
|
||||
* @brief Update detection
|
||||
|
@ -370,24 +366,6 @@ int csync_commit(CSYNC *ctx);
|
|||
*/
|
||||
int csync_destroy(CSYNC *ctx);
|
||||
|
||||
/**
|
||||
* @brief Add an additional exclude list.
|
||||
*
|
||||
* @param ctx The context to add the exclude list.
|
||||
*
|
||||
* @param path The path pointing to the file.
|
||||
*
|
||||
* @return 0 on success, less than 0 if an error occurred.
|
||||
*/
|
||||
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.
|
||||
*
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -47,37 +47,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.
|
||||
*
|
||||
|
|
|
@ -38,13 +38,12 @@
|
|||
#define NIL &_sentinel /* all leafs are sentinels */
|
||||
static c_rbnode_t _sentinel = {NULL, NIL, NIL, NULL, NULL, BLACK};
|
||||
|
||||
int c_rbtree_create(c_rbtree_t **rbtree, c_rbtree_compare_func *key_compare, c_rbtree_compare_func *data_compare) {
|
||||
c_rbtree_t *tree = NULL;
|
||||
void c_rbtree_create(c_rbtree_t **rbtree, c_rbtree_compare_func *key_compare, c_rbtree_compare_func *data_compare) {
|
||||
assert(rbtree);
|
||||
assert(key_compare);
|
||||
assert(data_compare);
|
||||
|
||||
if (rbtree == NULL || key_compare == NULL || data_compare == NULL) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
c_rbtree_t *tree = NULL;
|
||||
|
||||
tree = c_malloc(sizeof(*tree));
|
||||
tree->root = NIL;
|
||||
|
@ -53,8 +52,6 @@ int c_rbtree_create(c_rbtree_t **rbtree, c_rbtree_compare_func *key_compare, c_r
|
|||
tree->size = 0;
|
||||
|
||||
*rbtree = tree;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static c_rbnode_t *_rbtree_subtree_dup(const c_rbnode_t *node, c_rbtree_t *new_tree, c_rbnode_t *new_parent) {
|
||||
|
|
|
@ -135,10 +135,8 @@ struct c_rbnode_s {
|
|||
*
|
||||
* @param data_compare Callback function to compare a key as data with thee
|
||||
* data inside a red-black tree node.
|
||||
*
|
||||
* @return 0 on success, -1 if an error occurred with errno set.
|
||||
*/
|
||||
int c_rbtree_create(c_rbtree_t **rbtree, c_rbtree_compare_func *key_compare, c_rbtree_compare_func *data_compare);
|
||||
void c_rbtree_create(c_rbtree_t **rbtree, c_rbtree_compare_func *key_compare, c_rbtree_compare_func *data_compare);
|
||||
|
||||
/**
|
||||
* @brief Duplicate a red-black tree.
|
||||
|
|
|
@ -33,8 +33,7 @@ static void setup(void **state) {
|
|||
rc = system("mkdir -p /tmp/check_csync2");
|
||||
assert_int_equal(rc, 0);
|
||||
|
||||
rc = csync_create(&csync, "/tmp/check_csync1", "/tmp/check_csync2");
|
||||
assert_int_equal(rc, 0);
|
||||
csync_create(&csync, "/tmp/check_csync1", "/tmp/check_csync2");
|
||||
|
||||
*state = csync;
|
||||
}
|
||||
|
@ -49,10 +48,9 @@ static void setup_module(void **state) {
|
|||
rc = system("mkdir -p /tmp/check_csync2");
|
||||
assert_int_equal(rc, 0);
|
||||
|
||||
rc = csync_create(&csync, "/tmp/check_csync1", "dummy://foo/bar");
|
||||
assert_int_equal(rc, 0);
|
||||
csync_create(&csync, "/tmp/check_csync1", "dummy://foo/bar");
|
||||
|
||||
rc = csync_init(csync);
|
||||
csync_init(csync);
|
||||
*state = csync;
|
||||
}
|
||||
|
||||
|
@ -74,16 +72,6 @@ static void teardown(void **state) {
|
|||
*state = NULL;
|
||||
}
|
||||
|
||||
static void check_csync_commit_null(void **state)
|
||||
{
|
||||
int rc;
|
||||
|
||||
(void) state; /* unused */
|
||||
|
||||
rc = csync_commit(NULL);
|
||||
assert_int_equal(rc, -1);
|
||||
}
|
||||
|
||||
static void check_csync_commit(void **state)
|
||||
{
|
||||
CSYNC *csync = *state;
|
||||
|
@ -110,7 +98,6 @@ static void check_csync_commit_dummy(void **state)
|
|||
int torture_run_tests(void)
|
||||
{
|
||||
const UnitTest tests[] = {
|
||||
unit_test_setup_teardown(check_csync_commit_null, setup, teardown),
|
||||
unit_test_setup_teardown(check_csync_commit, setup, teardown),
|
||||
unit_test_setup_teardown(check_csync_commit_dummy, setup_module, teardown),
|
||||
};
|
||||
|
|
|
@ -42,8 +42,7 @@ static void check_csync_create(void **state)
|
|||
|
||||
(void) state; /* unused */
|
||||
|
||||
rc = csync_create(&csync, "/tmp/csync1", "/tmp/csync2");
|
||||
assert_int_equal(rc, 0);
|
||||
csync_create(&csync, "/tmp/csync1", "/tmp/csync2");
|
||||
|
||||
rc = csync_destroy(csync);
|
||||
assert_int_equal(rc, 0);
|
||||
|
|
|
@ -32,8 +32,7 @@ static void setup(void **state) {
|
|||
CSYNC *csync;
|
||||
int rc;
|
||||
|
||||
rc = csync_create(&csync, "/tmp/check_csync1", "/tmp/check_csync2");
|
||||
assert_int_equal(rc, 0);
|
||||
csync_create(&csync, "/tmp/check_csync1", "/tmp/check_csync2");
|
||||
|
||||
*state = csync;
|
||||
}
|
||||
|
@ -42,8 +41,7 @@ static void setup_init(void **state) {
|
|||
CSYNC *csync;
|
||||
int rc;
|
||||
|
||||
rc = csync_create(&csync, "/tmp/check_csync1", "/tmp/check_csync2");
|
||||
assert_int_equal(rc, 0);
|
||||
csync_create(&csync, "/tmp/check_csync1", "/tmp/check_csync2");
|
||||
|
||||
rc = csync_exclude_load(EXCLUDE_LIST_FILE, &(csync->excludes));
|
||||
assert_int_equal(rc, 0);
|
||||
|
@ -102,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);
|
||||
}
|
||||
|
||||
|
@ -241,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);
|
||||
}
|
||||
|
||||
|
@ -314,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
|
||||
|
||||
|
|
|
@ -33,8 +33,7 @@ static void setup(void **state) {
|
|||
rc = system("mkdir -p /tmp/check_csync2");
|
||||
assert_int_equal(rc, 0);
|
||||
|
||||
rc = csync_create(&csync, "/tmp/check_csync1", "/tmp/check_csync2");
|
||||
assert_int_equal(rc, 0);
|
||||
csync_create(&csync, "/tmp/check_csync1", "/tmp/check_csync2");
|
||||
|
||||
*state = csync;
|
||||
}
|
||||
|
@ -49,8 +48,7 @@ static void setup_module(void **state) {
|
|||
rc = system("mkdir -p /tmp/check_csync2");
|
||||
assert_int_equal(rc, 0);
|
||||
|
||||
rc = csync_create(&csync, "/tmp/check_csync1", "dummy://foo/bar");
|
||||
assert_int_equal(rc, 0);
|
||||
csync_create(&csync, "/tmp/check_csync1", "dummy://foo/bar");
|
||||
|
||||
*state = csync;
|
||||
}
|
||||
|
@ -73,34 +71,19 @@ static void teardown(void **state) {
|
|||
*state = NULL;
|
||||
}
|
||||
|
||||
static void check_csync_init_null(void **state)
|
||||
{
|
||||
int rc;
|
||||
|
||||
(void) state; /* unused */
|
||||
|
||||
rc = csync_init(NULL);
|
||||
assert_int_equal(rc, -1);
|
||||
}
|
||||
|
||||
static void check_csync_init(void **state)
|
||||
{
|
||||
CSYNC *csync = *state;
|
||||
int rc;
|
||||
|
||||
rc = csync_init(csync);
|
||||
assert_int_equal(rc, 0);
|
||||
csync_init(csync);
|
||||
|
||||
assert_int_equal(csync->status & CSYNC_STATUS_INIT, 1);
|
||||
|
||||
rc = csync_init(csync);
|
||||
assert_int_equal(rc, 1);
|
||||
}
|
||||
|
||||
int torture_run_tests(void)
|
||||
{
|
||||
const UnitTest tests[] = {
|
||||
unit_test_setup_teardown(check_csync_init_null, setup, teardown),
|
||||
unit_test_setup_teardown(check_csync_init, setup, teardown),
|
||||
unit_test_setup_teardown(check_csync_init, setup_module, teardown),
|
||||
};
|
||||
|
|
|
@ -37,8 +37,7 @@ static void setup(void **state) {
|
|||
rc = system("mkdir -p /tmp/check_csync2");
|
||||
assert_int_equal(rc, 0);
|
||||
|
||||
rc = csync_create(&csync, "/tmp/check_csync1", "/tmp/check_csync2");
|
||||
assert_int_equal(rc, 0);
|
||||
csync_create(&csync, "/tmp/check_csync1", "/tmp/check_csync2");
|
||||
|
||||
*state = csync;
|
||||
}
|
||||
|
|
|
@ -37,8 +37,7 @@ static void setup(void **state) {
|
|||
rc = system("mkdir -p /tmp/check_csync1");
|
||||
assert_int_equal(rc, 0);
|
||||
|
||||
rc = csync_create(&csync, "/tmp/check_csync1", "/tmp/check_csync2");
|
||||
assert_int_equal(rc, 0);
|
||||
csync_create(&csync, "/tmp/check_csync1", "/tmp/check_csync2");
|
||||
|
||||
csync->statedb.file = c_strdup( TESTDB );
|
||||
*state = csync;
|
||||
|
|
|
@ -42,10 +42,8 @@ static void setup(void **state)
|
|||
assert_int_equal(rc, 0);
|
||||
rc = system("mkdir -p /tmp/check_csync");
|
||||
assert_int_equal(rc, 0);
|
||||
rc = csync_create(&csync, "/tmp/check_csync1", "/tmp/check_csync2");
|
||||
assert_int_equal(rc, 0);
|
||||
rc = csync_init(csync);
|
||||
assert_int_equal(rc, 0);
|
||||
csync_create(&csync, "/tmp/check_csync1", "/tmp/check_csync2");
|
||||
csync_init(csync);
|
||||
|
||||
sqlite3 *db = NULL;
|
||||
rc = sqlite3_open_v2(TESTDB, &db, SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, NULL);
|
||||
|
|
|
@ -93,10 +93,8 @@ static void setup(void **state)
|
|||
assert_int_equal(rc, 0);
|
||||
rc = system("mkdir -p /tmp/check_csync2");
|
||||
assert_int_equal(rc, 0);
|
||||
rc = csync_create(&csync, "/tmp/check_csync1", "/tmp/check_csync2");
|
||||
assert_int_equal(rc, 0);
|
||||
rc = csync_init(csync);
|
||||
assert_int_equal(rc, 0);
|
||||
csync_create(&csync, "/tmp/check_csync1", "/tmp/check_csync2");
|
||||
csync_init(csync);
|
||||
|
||||
/* Create a new db with metadata */
|
||||
sqlite3 *db;
|
||||
|
@ -126,10 +124,8 @@ static void setup_ftw(void **state)
|
|||
assert_int_equal(rc, 0);
|
||||
rc = system("mkdir -p /tmp/check_csync2");
|
||||
assert_int_equal(rc, 0);
|
||||
rc = csync_create(&csync, "/tmp", "/tmp");
|
||||
assert_int_equal(rc, 0);
|
||||
rc = csync_init(csync);
|
||||
assert_int_equal(rc, 0);
|
||||
csync_create(&csync, "/tmp", "/tmp");
|
||||
csync_init(csync);
|
||||
|
||||
sqlite3 *db = NULL;
|
||||
rc = sqlite3_open_v2(TESTDB, &db, SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, NULL);
|
||||
|
|
|
@ -84,10 +84,8 @@ static void destructor(void *data) {
|
|||
|
||||
static void setup(void **state) {
|
||||
c_rbtree_t *tree = NULL;
|
||||
int rc;
|
||||
|
||||
rc = c_rbtree_create(&tree, key_cmp, data_cmp);
|
||||
assert_int_equal(rc, 0);
|
||||
c_rbtree_create(&tree, key_cmp, data_cmp);
|
||||
|
||||
*state = tree;
|
||||
}
|
||||
|
@ -97,8 +95,7 @@ static void setup_complete_tree(void **state) {
|
|||
int i = 0;
|
||||
int rc;
|
||||
|
||||
rc = c_rbtree_create(&tree, key_cmp, data_cmp);
|
||||
assert_int_equal(rc, 0);
|
||||
c_rbtree_create(&tree, key_cmp, data_cmp);
|
||||
|
||||
for (i = 0; i < 100; i++) {
|
||||
test_t *testdata = NULL;
|
||||
|
@ -131,31 +128,13 @@ static void check_c_rbtree_create_free(void **state)
|
|||
|
||||
(void) state; /* unused */
|
||||
|
||||
rc = c_rbtree_create(&tree, key_cmp, data_cmp);
|
||||
assert_int_equal(rc, 0);
|
||||
c_rbtree_create(&tree, key_cmp, data_cmp);
|
||||
assert_int_equal(tree->size, 0);
|
||||
|
||||
rc = c_rbtree_free(tree);
|
||||
assert_int_equal(rc, 0);
|
||||
}
|
||||
|
||||
static void check_c_rbtree_create_null(void **state)
|
||||
{
|
||||
c_rbtree_t *tree = NULL;
|
||||
int rc;
|
||||
|
||||
(void) state; /* unused */
|
||||
|
||||
rc = c_rbtree_create(NULL, key_cmp, data_cmp);
|
||||
assert_int_equal(rc, -1);
|
||||
|
||||
rc = c_rbtree_create(&tree, NULL, data_cmp);
|
||||
assert_int_equal(rc, -1);
|
||||
|
||||
rc = c_rbtree_create(&tree, key_cmp, NULL);
|
||||
assert_int_equal(rc, -1);
|
||||
}
|
||||
|
||||
static void check_c_rbtree_free_null(void **state)
|
||||
{
|
||||
int rc;
|
||||
|
@ -175,8 +154,7 @@ static void check_c_rbtree_insert_delete(void **state)
|
|||
|
||||
(void) state; /* unused */
|
||||
|
||||
rc = c_rbtree_create(&tree, key_cmp, data_cmp);
|
||||
assert_int_equal(rc, 0);
|
||||
c_rbtree_create(&tree, key_cmp, data_cmp);
|
||||
|
||||
testdata = malloc(sizeof(test_t));
|
||||
testdata->key = 42;
|
||||
|
@ -369,7 +347,6 @@ int torture_run_tests(void)
|
|||
{
|
||||
const UnitTest tests[] = {
|
||||
unit_test(check_c_rbtree_create_free),
|
||||
unit_test(check_c_rbtree_create_null),
|
||||
unit_test(check_c_rbtree_free_null),
|
||||
unit_test(check_c_rbtree_insert_delete),
|
||||
unit_test_setup_teardown(check_c_rbtree_insert_random, setup, teardown),
|
||||
|
|
|
@ -49,8 +49,7 @@ static void setup(void **state)
|
|||
rc = system("rm -rf /tmp/csync_test");
|
||||
assert_int_equal(rc, 0);
|
||||
|
||||
rc = csync_create(&csync, "/tmp/csync1", "/tmp/csync2");
|
||||
assert_int_equal(rc, 0);
|
||||
csync_create(&csync, "/tmp/csync1", "/tmp/csync2");
|
||||
|
||||
csync->replica = LOCAL_REPLICA;
|
||||
|
||||
|
|
|
@ -97,8 +97,7 @@ static void setup_testenv(void **state) {
|
|||
statevar *mystate = malloc( sizeof(statevar) );
|
||||
mystate->result = NULL;
|
||||
|
||||
rc = csync_create(&(mystate->csync), "/tmp/csync1", "/tmp/csync2");
|
||||
assert_int_equal(rc, 0);
|
||||
csync_create(&(mystate->csync), "/tmp/csync1", "/tmp/csync2");
|
||||
|
||||
mystate->csync->replica = LOCAL_REPLICA;
|
||||
|
||||
|
|
|
@ -385,26 +385,10 @@ int main(int argc, char **argv) {
|
|||
int restartCount = 0;
|
||||
restart_sync:
|
||||
|
||||
CSYNC *_csync_ctx;
|
||||
|
||||
if( csync_create( &_csync_ctx, options.source_dir.toUtf8(),
|
||||
remUrl.constData()) < 0 ) {
|
||||
qFatal("Unable to create csync-context!");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
csync_set_log_level(options.silent ? 1 : 11);
|
||||
|
||||
opts = &options;
|
||||
|
||||
if( csync_init( _csync_ctx ) < 0 ) {
|
||||
qFatal("Could not initialize csync!");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// ignore hidden files or not
|
||||
_csync_ctx->ignore_hidden_files = options.ignoreHiddenFiles;
|
||||
|
||||
if( !options.proxy.isNull() ) {
|
||||
QString host;
|
||||
int port = 0;
|
||||
|
@ -431,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);
|
||||
|
@ -460,30 +432,32 @@ 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()));
|
||||
|
||||
// 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++;
|
||||
|
|
|
@ -69,7 +69,6 @@ Folder::Folder(const FolderDefinition& definition,
|
|||
, _consecutiveFailingSyncs(0)
|
||||
, _consecutiveFollowUpSyncs(0)
|
||||
, _journal(definition.localPath)
|
||||
, _csync_ctx(0)
|
||||
{
|
||||
qsrand(QTime::currentTime().msec());
|
||||
_timeSinceLastSyncStart.start();
|
||||
|
@ -87,56 +86,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();
|
||||
|
||||
if( csync_create( &_csync_ctx, localpath.toUtf8().data(), url_string.toUtf8().data() ) < 0 ) {
|
||||
qDebug() << "Unable to create csync-context!";
|
||||
slotSyncError(tr("Unable to create csync-context"));
|
||||
_csync_ctx = 0;
|
||||
} else {
|
||||
csync_set_log_callback( csyncLogCatcher );
|
||||
csync_set_log_level( Logger::instance()->isNoop() ? 0 : 11 );
|
||||
|
||||
Q_ASSERT( _accountState );
|
||||
|
||||
if( csync_init( _csync_ctx ) < 0 ) {
|
||||
qDebug() << "Could not initialize csync!" << csync_get_status(_csync_ctx) << csync_get_status_string(_csync_ctx);
|
||||
QString errStr = SyncEngine::csyncErrorToString(CSYNC_STATUS(csync_get_status(_csync_ctx)));
|
||||
const char *errMsg = csync_get_status_string(_csync_ctx);
|
||||
if( errMsg ) {
|
||||
errStr += QLatin1String("<br/>");
|
||||
errStr += QString::fromUtf8(errMsg);
|
||||
}
|
||||
slotSyncError(errStr);
|
||||
csync_destroy(_csync_ctx);
|
||||
_csync_ctx = 0;
|
||||
}
|
||||
}
|
||||
return _csync_ctx;
|
||||
}
|
||||
|
||||
Folder::~Folder()
|
||||
{
|
||||
if( _engine ) {
|
||||
_engine->abort();
|
||||
_engine.reset(0);
|
||||
}
|
||||
// Destroy csync here.
|
||||
csync_destroy(_csync_ctx);
|
||||
}
|
||||
|
||||
void Folder::setAccountState( AccountState *account )
|
||||
|
@ -832,25 +787,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)
|
||||
|
@ -871,19 +820,10 @@ 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_callback( csyncLogCatcher );
|
||||
csync_set_log_level( Logger::instance()->isNoop() ? 0 : 11 );
|
||||
|
||||
if (isBusy()) {
|
||||
|
@ -903,18 +843,17 @@ void Folder::startSync(const QStringList &pathList)
|
|||
qDebug() << "*** Start syncing " << remoteUrl().toString() << " - client version"
|
||||
<< qPrintable(Theme::instance()->version());
|
||||
|
||||
if (! setIgnoredFiles())
|
||||
_engine.reset(new SyncEngine( _accountState->account(), path(), remoteUrl(), remotePath(), &_journal));
|
||||
// pass the setting if hidden files are to be ignored, will be read in csync_update
|
||||
_engine->setIgnoreHiddenFiles(_definition.ignoreHiddenFiles);
|
||||
|
||||
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");
|
||||
|
||||
|
|
|
@ -272,8 +272,6 @@ private slots:
|
|||
void slotNewBigFolderDiscovered(const QString &);
|
||||
|
||||
private:
|
||||
bool init();
|
||||
|
||||
bool setIgnoredFiles();
|
||||
|
||||
void bubbleUpSyncResult();
|
||||
|
@ -320,8 +318,6 @@ private:
|
|||
SyncJournalDb _journal;
|
||||
|
||||
ClientProxy _clientProxy;
|
||||
|
||||
CSYNC *_csync_ctx;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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,12 @@ public slots:
|
|||
/**
|
||||
* Reloads the exclude patterns from the registered paths.
|
||||
*/
|
||||
void reloadExcludes();
|
||||
bool reloadExcludes();
|
||||
|
||||
private:
|
||||
ExcludedFiles();
|
||||
~ExcludedFiles();
|
||||
|
||||
c_strlist_t* _excludes;
|
||||
// This is a pointer to the csync exclude list, its is owned by this class
|
||||
// but the pointer can be in a csync_context so that it can itself also query the list.
|
||||
c_strlist_t** _excludesPtr;
|
||||
QStringList _excludeFiles;
|
||||
mutable QReadWriteLock _mutex;
|
||||
};
|
||||
|
|
|
@ -56,10 +56,9 @@ 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)
|
||||
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 +78,28 @@ 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_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 +904,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)),
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -116,7 +116,7 @@ private slots:
|
|||
QVERIFY(parser.parse( testXml, &sizes, "/oc/remote.php/webdav/sharefolder" ));
|
||||
|
||||
QVERIFY(_success);
|
||||
QVERIFY(sizes.size() == 0 ); // No quota info in the XML
|
||||
QCOMPARE(sizes.size(), 1 ); // Quota info in the XML
|
||||
|
||||
QVERIFY(_items.contains("/oc/remote.php/webdav/sharefolder/quitte.pdf"));
|
||||
QVERIFY(_items.contains("/oc/remote.php/webdav/sharefolder"));
|
||||
|
|
Загрузка…
Ссылка в новой задаче