From 7eb3f901a6c7d009187104619851b169cad464eb Mon Sep 17 00:00:00 2001 From: Klaas Freitag Date: Wed, 3 Jul 2013 22:38:45 +0200 Subject: [PATCH] Experimental: Fix the mv and recreate case as described in mirall#731. Please note that this needs review and test and probably does not fully fix it. It just makes sure that renames are handled before PUTs. --- src/csync_propagate.c | 56 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/src/csync_propagate.c b/src/csync_propagate.c index 7dc37bc7f..941b6b474 100644 --- a/src/csync_propagate.c +++ b/src/csync_propagate.c @@ -1422,6 +1422,52 @@ static int _csync_propagation_cleanup(CSYNC *ctx) { return 0; } +static int _csync_propagation_rename_file_visitor(void *obj, void *data) { + csync_file_stat_t *st = NULL; + CSYNC *ctx = NULL; + int rc = 0; + + st = (csync_file_stat_t *) obj; + ctx = (CSYNC *) data; + + if (ctx->abort) { + CSYNC_LOG(CSYNC_LOG_PRIORITY_TRACE, "Aborted!"); + ctx->error_code = CSYNC_ERR_ABORTED; + return -1; + } + + switch(st->type) { + case CSYNC_FTW_TYPE_SLINK: + break; + case CSYNC_FTW_TYPE_FILE: + switch (st->instruction) { + case CSYNC_INSTRUCTION_RENAME: + if ((rc = _csync_rename_file(ctx, st)) < 0) { + CSYNC_LOG(CSYNC_LOG_PRIORITY_TRACE,"FAIL RENAME: %s",st->path); + goto err; + } + break; + default: + break; + } + break; + case CSYNC_FTW_TYPE_DIR: + /* + * We have to walk over the files first. If you create or rename a file + * in a directory on unix. The modification time of the directory gets + * changed. + */ + break; + default: + break; + } + + return rc; +err: + return -1; +} + + static int _csync_propagation_file_visitor(void *obj, void *data) { csync_file_stat_t *st = NULL; CSYNC *ctx = NULL; @@ -1447,12 +1493,6 @@ static int _csync_propagation_file_visitor(void *obj, void *data) { goto err; } break; - case CSYNC_INSTRUCTION_RENAME: - if ((rc = _csync_rename_file(ctx, st)) < 0) { - CSYNC_LOG(CSYNC_LOG_PRIORITY_TRACE,"FAIL RENAME: %s",st->path); - goto err; - } - break; case CSYNC_INSTRUCTION_SYNC: if ((rc = _csync_sync_file(ctx, st)) < 0) { CSYNC_LOG(CSYNC_LOG_PRIORITY_TRACE,"FAIL SYNC: %s",st->path); @@ -1567,6 +1607,10 @@ int csync_propagate_files(CSYNC *ctx) { break; } + if (c_rbtree_walk(tree, (void *) ctx, _csync_propagation_rename_file_visitor) < 0) { + return -1; + } + if (c_rbtree_walk(tree, (void *) ctx, _csync_propagation_file_visitor) < 0) { return -1; }