From 7ddfa79950d76316b4914daf7636b098f6c10a8d Mon Sep 17 00:00:00 2001 From: Klaas Freitag Date: Wed, 27 Jan 2016 14:10:52 +0100 Subject: [PATCH 1/3] csync_update: Use the csync defines rather than plain numbers. --- csync/src/csync_update.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/csync/src/csync_update.c b/csync/src/csync_update.c index bd0a4c73b1..1a30c81aa7 100644 --- a/csync/src/csync_update.c +++ b/csync/src/csync_update.c @@ -353,10 +353,12 @@ static int _csync_detect_update(CSYNC *ctx, const char *file, } /* translate the file type between the two stat types csync has. */ - if( tmp && tmp->type == 0 ) { + if( tmp && tmp->type == CSYNC_FTW_TYPE_FILE ) { tmp_vio_type = CSYNC_VIO_FILE_TYPE_REGULAR; - } else if( tmp && tmp->type == 2 ) { + } else if( tmp && tmp->type == CSYNC_FTW_TYPE_DIR) { tmp_vio_type = CSYNC_VIO_FILE_TYPE_DIRECTORY; + } else if( tmp && tmp->type == CSYNC_FTW_TYPE_SLINK ) { + tmp_vio_type = CSYNC_VIO_FILE_TYPE_SYMBOLIC_LINK; } else { tmp_vio_type = CSYNC_VIO_FILE_TYPE_UNKNOWN; } From 28907ec0c3fe41d3753a59cbea237ce3a65d999c Mon Sep 17 00:00:00 2001 From: Klaas Freitag Date: Wed, 27 Jan 2016 14:11:37 +0100 Subject: [PATCH 2/3] csync_update: Handle comparision of file types properly. Note that the structs use different enums for the file types, unfortunately. --- csync/src/csync_update.c | 52 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/csync/src/csync_update.c b/csync/src/csync_update.c index 1a30c81aa7..3274b9cc4f 100644 --- a/csync/src/csync_update.c +++ b/csync/src/csync_update.c @@ -106,6 +106,49 @@ static bool _last_db_return_error(CSYNC* ctx) { return ctx->statedb.lastReturnValue != SQLITE_OK && ctx->statedb.lastReturnValue != SQLITE_DONE && ctx->statedb.lastReturnValue != SQLITE_ROW; } +/* + * This static method is needed because the type members of the two structs use + * different enum values. A direct comparion is not neccessarily correct. + * + * tmp is csync_file_stat_t + * fs is csync_vio_file_stat_t with this vio type: + * enum csync_vio_file_type_e { + * CSYNC_VIO_FILE_TYPE_UNKNOWN, + * CSYNC_VIO_FILE_TYPE_REGULAR, + * CSYNC_VIO_FILE_TYPE_DIRECTORY, + * CSYNC_VIO_FILE_TYPE_FIFO, + * CSYNC_VIO_FILE_TYPE_SOCKET, + * CSYNC_VIO_FILE_TYPE_CHARACTER_DEVICE, + * CSYNC_VIO_FILE_TYPE_BLOCK_DEVICE, + * CSYNC_VIO_FILE_TYPE_SYMBOLIC_LINK + * }; + * + * csync_file_stat_t can be: + * CSYNC_FTW_TYPE_SKIP, CSYNC_FTW_TYPE_FILE + * CSYNC_FTW_TYPE_DIR, CSYNC_FTW_TYPE_SLINK + */ +static bool _csync_filetype_different( const csync_file_stat_t *tmp, const csync_vio_file_stat_t *fs) +{ + if( !(tmp && fs)) return false; + + if( tmp->type == CSYNC_FTW_TYPE_SKIP ) return true; + + if( tmp->type == CSYNC_FTW_TYPE_DIR && fs->type != CSYNC_VIO_FILE_TYPE_DIRECTORY ) + return true; + if( tmp->type == CSYNC_FTW_TYPE_FILE && fs->type != CSYNC_VIO_FILE_TYPE_REGULAR ) + return true; + if( tmp->type == CSYNC_FTW_TYPE_SLINK && fs->type != CSYNC_VIO_FILE_TYPE_SYMBOLIC_LINK ) + return true; + + if( fs->type == CSYNC_VIO_FILE_TYPE_DIRECTORY && tmp->type != CSYNC_FTW_TYPE_DIR ) + return true; + if( fs->type == CSYNC_VIO_FILE_TYPE_REGULAR && tmp->type != CSYNC_FTW_TYPE_FILE ) + return true; + if( fs->type == CSYNC_VIO_FILE_TYPE_SYMBOLIC_LINK && tmp->type != CSYNC_FTW_TYPE_SLINK ) + return true; + + return false; // both are NOT different. +} /* Return true if two mtime are considered equal * We consider mtime that are one hour difference to be equal if they are one hour appart @@ -274,8 +317,9 @@ static int _csync_detect_update(CSYNC *ctx, const char *file, st->instruction = CSYNC_INSTRUCTION_EVAL; // Preserve the EVAL flag later on if the type has changed. - if (tmp->type != fs->type) + if (_csync_filetype_different(tmp, fs)) { st->child_modified = 1; + } goto out; } @@ -303,8 +347,9 @@ static int _csync_detect_update(CSYNC *ctx, const char *file, } // Preserve the EVAL flag later on if the type has changed. - if (tmp->type != fs->type) + if (_csync_filetype_different(tmp, fs)) { st->child_modified = 1; + } st->instruction = CSYNC_INSTRUCTION_EVAL; goto out; @@ -391,8 +436,7 @@ static int _csync_detect_update(CSYNC *ctx, const char *file, return -1; } if(tmp ) { /* tmp existing at all */ - if ((tmp->type == CSYNC_FTW_TYPE_DIR && fs->type != CSYNC_VIO_FILE_TYPE_DIRECTORY) || - (tmp->type == CSYNC_FTW_TYPE_FILE && fs->type != CSYNC_VIO_FILE_TYPE_REGULAR)) { + if ( _csync_filetype_different(tmp, fs)) { CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "WARN: file types different is not!"); st->instruction = CSYNC_INSTRUCTION_NEW; goto out; From 57c7727479e1cf9d74b49e3127d693b31091394b Mon Sep 17 00:00:00 2001 From: Klaas Freitag Date: Fri, 29 Jan 2016 10:43:31 +0100 Subject: [PATCH 3/3] csync_update: Remove unneeded checks of previous commit. --- csync/src/csync_update.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/csync/src/csync_update.c b/csync/src/csync_update.c index 3274b9cc4f..90208d92a2 100644 --- a/csync/src/csync_update.c +++ b/csync/src/csync_update.c @@ -140,13 +140,6 @@ static bool _csync_filetype_different( const csync_file_stat_t *tmp, const csync if( tmp->type == CSYNC_FTW_TYPE_SLINK && fs->type != CSYNC_VIO_FILE_TYPE_SYMBOLIC_LINK ) return true; - if( fs->type == CSYNC_VIO_FILE_TYPE_DIRECTORY && tmp->type != CSYNC_FTW_TYPE_DIR ) - return true; - if( fs->type == CSYNC_VIO_FILE_TYPE_REGULAR && tmp->type != CSYNC_FTW_TYPE_FILE ) - return true; - if( fs->type == CSYNC_VIO_FILE_TYPE_SYMBOLIC_LINK && tmp->type != CSYNC_FTW_TYPE_SLINK ) - return true; - return false; // both are NOT different. }