From f8fdff885e077f8b1335bef8268d995a21830a15 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Tue, 2 Jul 2013 22:58:50 +0200 Subject: [PATCH] Make sure to write the errors in the DB as well. If a file can't be uploaded, we still need to write it into the DB if it was in the DB before, with the old timestamp. --- src/csync_util.c | 66 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 14 deletions(-) diff --git a/src/csync_util.c b/src/csync_util.c index 162be0e5d..813f28b4a 100644 --- a/src/csync_util.c +++ b/src/csync_util.c @@ -34,6 +34,7 @@ #define CSYNC_LOG_CATEGORY_NAME "csync.util" #include "csync_log.h" +#include "csync_statedb.h" typedef struct { const char *instr_str; @@ -257,6 +258,48 @@ out: return rc; } +static int _fix_errors_visitor(void *obj, void *data) { + csync_file_stat_t *fs = NULL; + csync_file_stat_t *tfs = NULL; + + CSYNC *ctx = NULL; + + int rc = -1; + + fs = (csync_file_stat_t *) obj; + ctx = (CSYNC *) data; + + /* search for ERROR */ + if (fs->instruction != CSYNC_INSTRUCTION_ERROR) { + rc = 0; + goto out; + } + + /* check if the file is new or has been synced */ + tfs = csync_statedb_get_stat_by_hash(ctx, fs->phash); + if (tfs == NULL) { + rc = 0; + goto out; + } + + /* update file stat */ + fs->inode = tfs->inode; + fs->modtime = tfs->modtime; + + fs->instruction = CSYNC_INSTRUCTION_UPDATED; + + rc = 0; +out: + csync_file_stat_free(tfs); + + if (rc != 0) { + fs->instruction = CSYNC_INSTRUCTION_ERROR; + } + + return rc; +} + + /* * merge the local tree with the new files from remote and update the * inode numbers @@ -264,6 +307,15 @@ out: int csync_merge_file_trees(CSYNC *ctx) { int rc = -1; + /* walk over the local tree, in case of error take the value from the database */ + ctx->current = REMOTE_REPLICA; + ctx->replica = ctx->remote.type; + + rc = c_rbtree_walk(ctx->local.tree, ctx, _fix_errors_visitor); + if (rc < 0) { + goto out; + } + /* walk over remote tree, stat on local system */ ctx->current = LOCAL_REPLICA; ctx->replica = ctx->local.type; @@ -272,20 +324,6 @@ int csync_merge_file_trees(CSYNC *ctx) { if (rc < 0) { goto out; } - -#if 0 - /* We don't have to merge the remote tree atm. */ - - /* walk over local tree, stat on remote system */ - ctx->current = REMOTE_REPLICA; - ctx->replica = ctx->remote.type; - - rc = c_rbtree_walk(ctx->local.tree, ctx, _merge_file_trees_visitor); - if (rc < 0) { - goto out; - } -#endif - out: return rc; }