diff --git a/src/csync.c b/src/csync.c index 285c715caf..ad9e5fe081 100644 --- a/src/csync.c +++ b/src/csync.c @@ -525,6 +525,13 @@ int csync_propagate(CSYNC *ctx) { } ctx->error_code = CSYNC_ERR_NONE; + rc = csync_init_overall_progress(ctx); + if (rc < 0) { + if( ctx->error_code == CSYNC_ERR_NONE ) + ctx->error_code = csync_errno_to_csync_error( CSYNC_ERR_PROPAGATE); + return -1; + } + ctx->current = REMOTE_REPLICA; ctx->replica = ctx->remote.type; rc = csync_propagate_renames(ctx); diff --git a/src/csync_propagate.c b/src/csync_propagate.c index 5394c1e636..dcb4f65df0 100644 --- a/src/csync_propagate.c +++ b/src/csync_propagate.c @@ -659,7 +659,7 @@ start_fd_based: /* Notify the overall progress */ if (ctx->callbacks.overall_progress_cb) { ctx->progress.byte_current += st->size; - ctx->callbacks.overall_progress_cb(duri, ++ctx->progress.current_file_no, ctx->progress.file_count, + ctx->callbacks.overall_progress_cb(duri, ctx->progress.current_file_no++, ctx->progress.file_count, ctx->progress.byte_current, ctx->progress.byte_sum, ctx->callbacks.userdata); } @@ -1631,6 +1631,44 @@ int csync_propagate_rename_file(CSYNC *ctx, csync_file_stat_t *st) { return _csync_rename_file(ctx, st); } +/* Count the files to transmit for both up- and download, ie. in both replicas. */ +int csync_init_overall_progress(CSYNC *ctx) { + + if (ctx == NULL) { + return -1; + } + + if (ctx->callbacks.overall_progress_cb == NULL) { + /* No progress callback, no need to count */ + return 0; + } + + ctx->current = REMOTE_REPLICA; + ctx->replica = ctx->remote.type; + + if (c_rbtree_walk(ctx->remote.tree, (void *) ctx, _csync_propagation_file_count_visitor) < 0) { + ctx->error_code = CSYNC_ERR_TREE; + return -1; + } + ctx->current = LOCAL_REPLICA; + ctx->replica = ctx->local.type; + + if (c_rbtree_walk(ctx->local.tree, (void *) ctx, _csync_propagation_file_count_visitor) < 0) { + ctx->error_code = CSYNC_ERR_TREE; + return -1; + } + + /* Notify the overall progress */ + if (ctx->progress.file_count >0) { + ctx->progress.current_file_no = 1; /* start with file 1 */ + } + ctx->callbacks.overall_progress_cb("", ctx->progress.current_file_no, ctx->progress.file_count, + ctx->progress.byte_current, ctx->progress.byte_sum, + ctx->callbacks.userdata); + + return 0; +} + int csync_propagate_files(CSYNC *ctx) { c_rbtree_t *tree = NULL; @@ -1645,17 +1683,6 @@ int csync_propagate_files(CSYNC *ctx) { break; } - /* If there is a overall progress callback set, count the number of files first. */ - if (ctx->callbacks.overall_progress_cb) { - if (c_rbtree_walk(tree, (void *) ctx, _csync_propagation_file_count_visitor) < 0) { - return -1; - } - /* Notify the overall progress */ - ctx->callbacks.overall_progress_cb("", ctx->progress.current_file_no, ctx->progress.file_count, - ctx->progress.byte_current, ctx->progress.byte_sum, - ctx->callbacks.userdata); - } - if (c_rbtree_walk(tree, (void *) ctx, _csync_propagation_file_visitor) < 0) { return -1; } diff --git a/src/csync_propagate.h b/src/csync_propagate.h index ce3249f13e..660ab906ec 100644 --- a/src/csync_propagate.h +++ b/src/csync_propagate.h @@ -66,6 +66,9 @@ int csync_propagate_files(CSYNC *ctx); int csync_propagate_rename_file(CSYNC *ctx, csync_file_stat_t *st); + +int csync_init_overall_progress(CSYNC *ctx); + /** * }@ */