From e0807cba1b164fcf409cb71e3da2f8f7b88637a9 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 13 Jan 2009 15:50:44 +0100 Subject: [PATCH] Add a check if we are operating remote on a unix filesystem. This extends the exclude function. Maybe we should do this for the local too. --- src/csync.c | 7 +++++++ src/csync_exclude.c | 20 ++++++++++++++++++++ src/csync_private.h | 1 + src/csync_util.c | 34 ++++++++++++++++++++++++++++++++++ src/csync_util.h | 2 ++ 5 files changed, 64 insertions(+) diff --git a/src/csync.c b/src/csync.c index dbdb9c9b4..67bace52d 100644 --- a/src/csync.c +++ b/src/csync.c @@ -112,6 +112,7 @@ int csync_create(CSYNC **csync, const char *local, const char *remote) { ctx->options.max_depth = MAX_DEPTH; ctx->options.max_time_difference = MAX_TIME_DIFFERENCE; + ctx->options.unix_filesystem = 0; ctx->pwd.uid = getuid(); ctx->pwd.euid = geteuid(); @@ -274,6 +275,12 @@ int csync_init(CSYNC *ctx) { goto out; } + if (csync_unix_filesystem(ctx) < 0) { + CSYNC_LOG(CSYNC_LOG_PRIORITY_FATAL, "Could not detect filesystem type."); + rc = -1; + goto out; + } + if (c_rbtree_create(&ctx->local.tree, _key_cmp, _data_cmp) < 0) { rc = -1; goto out; diff --git a/src/csync_exclude.c b/src/csync_exclude.c index 90e86b01c..6328e5048 100644 --- a/src/csync_exclude.c +++ b/src/csync_exclude.c @@ -105,6 +105,26 @@ void csync_exclude_destroy(CSYNC *ctx) { int csync_excluded(CSYNC *ctx, const char *path) { size_t i; + const char *p; + + if (! ctx->options.unix_filesystem) { + for (p = path; *p; p++) { + switch (*p) { + case '/': + case '\\': + case ':': + case '?': + case '*': + case '"': + case '>': + case '<': + case '|': + return 1; + default: + break; + } + } + } if (ctx->excludes == NULL) { return 0; diff --git a/src/csync_private.h b/src/csync_private.h index 967403b60..378adcf73 100644 --- a/src/csync_private.h +++ b/src/csync_private.h @@ -109,6 +109,7 @@ struct csync_s { int max_depth; int max_time_difference; int sync_symbolic_links; + int unix_filesystem; char *config_dir; } options; diff --git a/src/csync_util.c b/src/csync_util.c index a71b8b2d3..ed63bb6b3 100644 --- a/src/csync_util.c +++ b/src/csync_util.c @@ -253,3 +253,37 @@ out: return rc; } +int csync_unix_filesystem(CSYNC *ctx) { + int rc = -1; + char *uri = NULL; + csync_vio_handle_t *fp = NULL; + + ctx->options.unix_filesystem = 0; + + if (asprintf(&uri, "%s/csync_file*test.ctmp", ctx->remote.uri) < 0) { + rc = -1; + goto out; + } + + ctx->replica = ctx->remote.type; + fp = csync_vio_creat(ctx, uri, 0644); + if (fp == NULL) { + rc = 0; + CSYNC_LOG(CSYNC_LOG_PRIORITY_INFO, + "Disabled unix filesystem synchronization"); + goto out; + } + csync_vio_close(ctx, fp); + + ctx->options.unix_filesystem = 1; + CSYNC_LOG(CSYNC_LOG_PRIORITY_INFO, "Enabled unix filesystem synchronization"); + + rc = 1; + +out: + csync_vio_unlink(ctx, uri); + SAFE_FREE(uri); + + return rc; +} + diff --git a/src/csync_util.h b/src/csync_util.h index cff1ef777..d04e4542e 100644 --- a/src/csync_util.h +++ b/src/csync_util.h @@ -31,4 +31,6 @@ void csync_memstat_check(void); int csync_merge_file_trees(CSYNC *ctx); +int csync_unix_filesystem(CSYNC *ctx); + #endif /* _CSYNC_UTIL_H */