示例#1
0
文件: csync.c 项目: aduchate/mirall
int csync_destroy(CSYNC *ctx) {
  int rc = 0;

  if (ctx == NULL) {
    errno = EBADF;
    return -1;
  }
  ctx->status_code = CSYNC_STATUS_OK;

  if (ctx->statedb.db != NULL
      && csync_statedb_close(ctx) < 0) {
    CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "ERR: closing of statedb failed.");
    rc = -1;
  }
  ctx->statedb.db = NULL;

  /* destroy exclude list */
  csync_exclude_destroy(ctx);

  _csync_clean_ctx(ctx);

  SAFE_FREE(ctx->local.uri);
  SAFE_FREE(ctx->remote.uri);
  SAFE_FREE(ctx->options.config_dir);
  SAFE_FREE(ctx->error_string);

#ifdef WITH_ICONV
  c_close_iconv();
#endif

  SAFE_FREE(ctx);

  return rc;
}
示例#2
0
文件: csync.c 项目: aduchate/mirall
int csync_set_iconv_codec(const char *from)
{
  c_close_iconv();

  if (from != NULL) {
    c_setup_iconv(from);
  }

  return 0;
}
示例#3
0
文件: csync.c 项目: gco/csync
int csync_destroy(CSYNC *ctx) {
  char *lock = NULL;
  int rc;

  if (ctx == NULL) {
    errno = EBADF;
    return -1;
  }
  ctx->status_code = CSYNC_STATUS_OK;

  csync_vio_shutdown(ctx);

  rc = _merge_and_write_statedb(ctx);
  if (rc < 0) {
    CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "destroy: Merge and Write database failed!");
    if (ctx->status_code == CSYNC_STATUS_OK) {
      ctx->status_code = CSYNC_STATUS_STATEDB_WRITE_ERROR;
    }
    /* The other steps happen anyway, what else can we do? */
  }

  /* clear exclude list */
  csync_exclude_destroy(ctx);

#ifndef _WIN32
  /* remove the lock file */
  rc = asprintf(&lock, "%s/%s", ctx->options.config_dir, CSYNC_LOCK_FILE);
  if (rc > 0) {
    csync_lock_remove(lock);
  }
#endif

  /* destroy the rbtrees */
  rc = c_rbtree_size(ctx->local.tree);
  if (rc > 0) {
    c_rbtree_destroy(ctx->local.tree, _tree_destructor);
  }

  rc = c_rbtree_size(ctx->remote.tree);
  if (rc > 0) {
    c_rbtree_destroy(ctx->remote.tree, _tree_destructor);
  }

  /* free memory */
  c_rbtree_free(ctx->local.tree);
  c_list_free(ctx->local.list);
  c_rbtree_free(ctx->remote.tree);
  c_list_free(ctx->remote.list);
  SAFE_FREE(ctx->local.uri);
  SAFE_FREE(ctx->remote.uri);
  SAFE_FREE(ctx->options.config_dir);
  SAFE_FREE(ctx->statedb.file);
  SAFE_FREE(ctx->error_string);

#ifdef WITH_ICONV
  c_close_iconv();
#endif

  SAFE_FREE(ctx);

  SAFE_FREE(lock);

  return 0;
}