From ce554eb44af07888068294a4bc4995e9036a54d4 Mon Sep 17 00:00:00 2001 From: Klaas Freitag Date: Mon, 2 Sep 2013 17:23:02 +0200 Subject: [PATCH] Let csync exclude report the exclude reason. --- src/csync_exclude.c | 25 ++++++++++--------------- src/csync_exclude.h | 10 +++++++++- src/csync_update.c | 16 ++++++++++++---- 3 files changed, 31 insertions(+), 20 deletions(-) diff --git a/src/csync_exclude.c b/src/csync_exclude.c index 81f828db4..792d36c6a 100644 --- a/src/csync_exclude.c +++ b/src/csync_exclude.c @@ -129,18 +129,18 @@ void csync_exclude_destroy(CSYNC *ctx) { c_strlist_destroy(ctx->excludes); } -int csync_excluded(CSYNC *ctx, const char *path) { +CSYNC_EXCLUDE_TYPE csync_excluded(CSYNC *ctx, const char *path) { size_t i; const char *p; char *bname; int rc; - int match = 0; + CSYNC_EXCLUDE_TYPE match = CSYNC_NOT_EXCLUDED; + CSYNC_EXCLUDE_TYPE type = CSYNC_NOT_EXCLUDED; const char *it; - int type = 0; /* exclude the lock file */ if (c_streq( path, CSYNC_LOCK_FILE )) { - return 1; + return CSYNC_FILE_SILENTLY_EXCLUDED; } if (! ctx->options.unix_extensions) { @@ -154,26 +154,21 @@ int csync_excluded(CSYNC *ctx, const char *path) { case '>': case '<': case '|': - return 1; + return CSYNC_FILE_EXCLUDE_INVALID_CHAR; default: break; } } } - rc = csync_fnmatch(".csync_journal.db*", path, 0); - if (rc == 0) { - return 1; - } - bname = c_basename(path); if (bname == NULL) { - return 0; + return CSYNC_NOT_EXCLUDED; } rc = csync_fnmatch(".csync_journal.db*", bname, 0); if (rc == 0) { - match = 1; + match = CSYNC_FILE_SILENTLY_EXCLUDED; goto out; } @@ -181,13 +176,13 @@ int csync_excluded(CSYNC *ctx, const char *path) { goto out; } - for (i = 0; match == 0 && i < ctx->excludes->count; i++) { + for (i = 0; match == CSYNC_NOT_EXCLUDED && i < ctx->excludes->count; i++) { it = ctx->excludes->vector[i]; - type = 1; + type = CSYNC_FILE_EXCLUDE_LIST; /* Ecludes starting with ']' means it can be cleanup */ if (it[0] == ']') { ++it; - type = 2; + type = CSYNC_FILE_EXCLUDE_AND_REMOVE; } rc = csync_fnmatch(it, path, 0); diff --git a/src/csync_exclude.h b/src/csync_exclude.h index 419cfdeb9..fdafc5f13 100644 --- a/src/csync_exclude.h +++ b/src/csync_exclude.h @@ -21,6 +21,14 @@ #ifndef _CSYNC_EXCLUDE_H #define _CSYNC_EXCLUDE_H +enum csync_exclude_type_e { + CSYNC_NOT_EXCLUDED = 0, + CSYNC_FILE_SILENTLY_EXCLUDED, + CSYNC_FILE_EXCLUDE_AND_REMOVE, + CSYNC_FILE_EXCLUDE_LIST, + CSYNC_FILE_EXCLUDE_INVALID_CHAR +}; +typedef enum csync_exclude_type_e CSYNC_EXCLUDE_TYPE; /** * @brief Load exclude list * @@ -55,7 +63,7 @@ void csync_exclude_destroy(CSYNC *ctx); * * @return 2 if excluded and needs cleanup, 1 if excluded, 0 if not. */ -int csync_excluded(CSYNC *ctx, const char *path); +CSYNC_EXCLUDE_TYPE csync_excluded(CSYNC *ctx, const char *path); #endif /* _CSYNC_EXCLUDE_H */ diff --git a/src/csync_update.c b/src/csync_update.c index f06ef5d49..917c6192a 100644 --- a/src/csync_update.c +++ b/src/csync_update.c @@ -87,7 +87,7 @@ static int _csync_detect_update(CSYNC *ctx, const char *file, const char *path = NULL; csync_file_stat_t *st = NULL; csync_file_stat_t *tmp = NULL; - int excluded; + CSYNC_EXCLUDE_TYPE excluded; if ((file == NULL) || (fs == NULL)) { errno = EINVAL; @@ -118,9 +118,9 @@ static int _csync_detect_update(CSYNC *ctx, const char *file, /* Check if file is excluded */ excluded = csync_excluded(ctx, path); - if (excluded) { + if (excluded != CSYNC_NOT_EXCLUDED) { CSYNC_LOG(CSYNC_LOG_PRIORITY_TRACE, "%s excluded (%d)", path, excluded); - if (excluded == 2) { + if (excluded == CSYNC_FILE_EXCLUDE_AND_REMOVE) { switch (ctx->current) { case LOCAL_REPLICA: ctx->local.ignored_cleanup = c_list_append(ctx->local.ignored_cleanup, c_strdup(path)); @@ -183,7 +183,7 @@ static int _csync_detect_update(CSYNC *ctx, const char *file, st->instruction = CSYNC_INSTRUCTION_NONE; goto out; } - if (excluded > 0 || type == CSYNC_FTW_TYPE_SLINK) { + if (excluded > CSYNC_NOT_EXCLUDED || type == CSYNC_FTW_TYPE_SLINK) { st->instruction = CSYNC_INSTRUCTION_IGNORE; goto out; } @@ -249,6 +249,14 @@ static int _csync_detect_update(CSYNC *ctx, const char *file, out: + /* Set the ignored error string. */ + if (st->instruction == CSYNC_INSTRUCTION_IGNORE) { + if (excluded == CSYNC_FILE_EXCLUDE_LIST) { + st->error_string = c_strdup("File listed on ignore list."); + } else if (excluded == CSYNC_FILE_EXCLUDE_INVALID_CHAR) { + st->error_string = c_strdup("File contains invalid characters."); + } + } if (st->instruction != CSYNC_INSTRUCTION_NONE && st->instruction != CSYNC_INSTRUCTION_IGNORE && type != CSYNC_FTW_TYPE_DIR) { st->child_modified = 1;