static int _csync_propagation_cleanup(CSYNC *ctx) { c_list_t *list = NULL; c_list_t *walk = NULL; char *uri = NULL; char *dir = NULL; switch (ctx->current) { case LOCAL_REPLICA: list = ctx->local.list; uri = ctx->local.uri; break; case REMOTE_REPLICA: list = ctx->remote.list; uri = ctx->remote.uri; break; default: break; } if (list == NULL) { ctx->status_code = CSYNC_STATUS_MEMORY_ERROR; return 0; } list = c_list_sort(list, _csync_cleanup_cmp); if (list == NULL) { ctx->status_code = CSYNC_STATUS_MEMORY_ERROR; return -1; } for (walk = c_list_last(list); walk != NULL; walk = c_list_prev(walk)) { csync_file_stat_t *st = NULL; st = (csync_file_stat_t *) walk->data; if (asprintf(&dir, "%s/%s", uri, st->path) < 0) { ctx->status_code = CSYNC_STATUS_MEMORY_ERROR; return -1; } if (csync_vio_rmdir(ctx, dir) < 0) { /* Write it back to statedb, that we try to delete it next time. */ st->instruction = CSYNC_INSTRUCTION_NONE; } else { st->instruction = CSYNC_INSTRUCTION_DELETED; } CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "CLEANUP dir: %s", dir); SAFE_FREE(dir); } return 0; }
/* reset all the list to empty. * used by csync_commit and csync_destroy */ static void _csync_clean_ctx(CSYNC *ctx) { c_list_t * walk; /* destroy the rbtrees */ if (c_rbtree_size(ctx->local.tree) > 0) { c_rbtree_destroy(ctx->local.tree, _tree_destructor); } if (c_rbtree_size(ctx->remote.tree) > 0) { c_rbtree_destroy(ctx->remote.tree, _tree_destructor); } csync_rename_destroy(ctx); for (walk = c_list_last(ctx->local.ignored_cleanup); walk != NULL; walk = c_list_prev(walk)) { SAFE_FREE(walk->data); } for (walk = c_list_last(ctx->remote.ignored_cleanup); walk != NULL; walk = c_list_prev(walk)) { SAFE_FREE(walk->data); } /* free memory */ c_rbtree_free(ctx->local.tree); c_list_free(ctx->local.list); c_list_free(ctx->local.ignored_cleanup); c_rbtree_free(ctx->remote.tree); c_list_free(ctx->remote.list); c_list_free(ctx->remote.ignored_cleanup); ctx->remote.list = 0; ctx->local.list = 0; ctx->remote.ignored_cleanup = 0; ctx->local.ignored_cleanup = 0; SAFE_FREE(ctx->statedb.file); }