示例#1
0
int csync_propagate_files(CSYNC *ctx) {
  c_rbtree_t *tree = NULL;

  switch (ctx->current) {
    case LOCAL_REPLICA:
      tree = ctx->local.tree;
      break;
    case REMOTE_REPLCIA:
      tree = ctx->remote.tree;
      break;
    default:
      break;
  }

  if (c_rbtree_walk(tree, (void *) ctx, _csync_propagation_file_visitor) < 0) {
    return -1;
  }

  if (c_rbtree_walk(tree, (void *) ctx, _csync_propagation_dir_visitor) < 0) {
    return -1;
  }

  if (_csync_propagation_cleanup(ctx) < 0) {
    return -1;
  }

  return 0;
}
示例#2
0
static void check_c_rbtree_walk_null(void **state)
{
    c_rbtree_t *tree = *state;
    int rc, i = 42;
    test_t *testdata;
    c_rbnode_t *node;

    rc = c_rbtree_check_sanity(tree);
    assert_int_equal(rc, 0);

    testdata = (test_t *) malloc(sizeof(test_t));
    testdata->key = 42;

    rc = c_rbtree_walk(NULL, testdata, visitor);
    assert_int_equal(rc, -1);
    assert_int_equal(errno, EINVAL);

    rc = c_rbtree_walk(tree, NULL, visitor);
    assert_int_equal(rc, -1);
    assert_int_equal(errno, EINVAL);

    rc = c_rbtree_walk(tree, testdata, NULL);
    assert_int_equal(rc, -1);
    assert_int_equal(errno, EINVAL);

    /* find the node with the key 42 */
    node = c_rbtree_find(tree, (void *) &i);
    assert_non_null(node);

    free(testdata);
}
示例#3
0
文件: csync.c 项目: aduchate/mirall
/*
 * treewalk function, called from its wrappers below.
 *
 * it encapsulates the user visitor function, the filter and the userdata
 * into a treewalk_context structure and calls the rb treewalk function,
 * which calls the local _csync_treewalk_visitor in this module.
 * The user visitor is called from there.
 */
static int _csync_walk_tree(CSYNC *ctx, c_rbtree_t *tree, csync_treewalk_visit_func *visitor, int filter)
{
    _csync_treewalk_context tw_ctx;
    int rc = -1;

    if (ctx == NULL) {
        errno = EBADF;
        return rc;
    }

    if (visitor == NULL || tree == NULL) {
        ctx->status_code = CSYNC_STATUS_PARAM_ERROR;
        return rc;
    }
    
    tw_ctx.userdata = ctx->callbacks.userdata;
    tw_ctx.user_visitor = visitor;
    tw_ctx.instruction_filter = filter;

    ctx->callbacks.userdata = &tw_ctx;

    rc = c_rbtree_walk(tree, (void*) ctx, _csync_treewalk_visitor);
    if( rc < 0 ) {
      if( ctx->status_code == CSYNC_STATUS_OK )
          ctx->status_code = csync_errno_to_status(errno, CSYNC_STATUS_TREE_ERROR);
    }
    ctx->callbacks.userdata = tw_ctx.userdata;

    return rc;
}
示例#4
0
/*
 * treewalk function, called from its wrappers below.
 *
 * it encapsulates the user visitor function, the filter and the userdata
 * into a treewalk_context structure and calls the rb treewalk function,
 * which calls the local _csync_treewalk_visitor in this module.
 * The user visitor is called from there.
 */
static int _csync_walk_tree(CSYNC *ctx, c_rbtree_t *tree, csync_treewalk_visit_func *visitor, int filter)
{
    _csync_treewalk_context tw_ctx;
    int rc = -1;

    if (ctx == NULL) {
      errno = EBADF;
      return -1;
    }
    ctx->error_code = CSYNC_ERR_NONE;

    if(!(visitor && tree)) {
      ctx->error_code =  CSYNC_ERR_PARAM;
      return rc;
    }
    
    tw_ctx.userdata = ctx->userdata;
    tw_ctx.user_visitor = visitor;
    tw_ctx.instruction_filter = filter;

    ctx->userdata = &tw_ctx;

    rc = c_rbtree_walk(tree, (void*) ctx, _csync_treewalk_visitor);
    if( rc < 0 ) 
        ctx->error_code = CSYNC_ERR_TREE;
    
    ctx->userdata = tw_ctx.userdata;

    return rc;
}
示例#5
0
int csync_reconcile_updates(CSYNC *ctx) {
  int rc;
  c_rbtree_t *tree = NULL;

  switch (ctx->current) {
    case LOCAL_REPLICA:
      tree = ctx->local.tree;
      break;
    case REMOTE_REPLCIA:
      tree = ctx->remote.tree;
      break;
    default:
      break;
  }

  rc = c_rbtree_walk(tree, (void *) ctx, _csync_merge_algorithm_visitor);

  return rc;
}
示例#6
0
int csync_statedb_insert_metadata(CSYNC *ctx) {
  c_strlist_t *result = NULL;

  if (c_rbtree_walk(ctx->local.tree, ctx, _insert_metadata_visitor) < 0) {
    return -1;
  }

  if (csync_statedb_insert(ctx, "INSERT INTO metadata SELECT * FROM metadata_temp;") < 0) {
    return -1;
  }

  result = csync_statedb_query(ctx, "DROP TABLE metadata_temp;");
  if (result == NULL) {
    return -1;
  }

  c_strlist_destroy(result);

  return 0;
}
示例#7
0
int csync_reconcile_updates(CSYNC *ctx) {
  int rc;
  c_rbtree_t *tree = NULL;

  switch (ctx->current) {
    case LOCAL_REPLICA:
      tree = ctx->local.tree;
      break;
    case REMOTE_REPLICA:
      tree = ctx->remote.tree;
      break;
    default:
      break;
  }

  rc = c_rbtree_walk(tree, (void *) ctx, _csync_merge_algorithm_visitor);
  if( rc < 0 ) {
    ctx->status_code = CSYNC_STATUS_RECONCILE_ERROR;
  }
  return rc;
}
示例#8
0
static void check_c_rbtree_walk(void **state)
{
    c_rbtree_t *tree = *state;
    int rc, i = 42;
    test_t *testdata;
    c_rbnode_t *node;

    rc = c_rbtree_check_sanity(tree);
    assert_int_equal(rc, 0);

    testdata = (test_t *) c_malloc(sizeof(test_t));
    testdata->key = 42;

    rc = c_rbtree_walk(tree, testdata, visitor);
    assert_int_equal(rc, 0);

    /* find the node with the key 42 */
    node = c_rbtree_find(tree, (void *) &i);
    assert_non_null(node);
    free(testdata);

    testdata = (test_t *) c_rbtree_node_data(node);
    assert_int_equal(testdata->number, 42);
}