Added ability to limit the csync run to the local tree only.

That gives apps the chance to use the efficient treewalk of csync
to get information on the tree.

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
Klaas Freitag 2012-02-27 12:18:02 +01:00 committed by Andreas Schneider
parent 53263a2685
commit 871dde4911
3 changed files with 76 additions and 30 deletions

View file

@ -116,6 +116,7 @@ int csync_create(CSYNC **csync, const char *local, const char *remote) {
ctx->options.max_time_difference = MAX_TIME_DIFFERENCE;
ctx->options.unix_extensions = 0;
ctx->options.with_conflict_copys=false;
ctx->options.local_only_mode = false;
ctx->pwd.uid = getuid();
ctx->pwd.euid = geteuid();
@ -261,7 +262,7 @@ int csync_init(CSYNC *ctx) {
ctx->local.type = LOCAL_REPLICA;
/* check for uri */
if (csync_fnmatch("*://*", ctx->remote.uri, 0) == 0) {
if ( !ctx->options.local_only_mode && csync_fnmatch("*://*", ctx->remote.uri, 0) == 0) {
size_t len;
len = strstr(ctx->remote.uri, "://") - ctx->remote.uri;
/* get protocol */
@ -294,23 +295,25 @@ retry_vio_init:
ctx->remote.type = LOCAL_REPLICA;
}
timediff = csync_timediff(ctx);
if (timediff > ctx->options.max_time_difference) {
CSYNC_LOG(CSYNC_LOG_PRIORITY_FATAL,
"Clock skew detected. The time difference is greater than %d seconds!",
ctx->options.max_time_difference);
rc = -1;
goto out;
} else if (timediff < 0) {
CSYNC_LOG(CSYNC_LOG_PRIORITY_FATAL, "Synchronisation is not possible!");
rc = -1;
goto out;
}
if( !ctx->options.local_only_mode ) {
timediff = csync_timediff(ctx);
if (timediff > ctx->options.max_time_difference) {
CSYNC_LOG(CSYNC_LOG_PRIORITY_FATAL,
"Clock skew detected. The time difference is greater than %d seconds!",
ctx->options.max_time_difference);
rc = -1;
goto out;
} else if (timediff < 0) {
CSYNC_LOG(CSYNC_LOG_PRIORITY_FATAL, "Synchronisation is not possible!");
rc = -1;
goto out;
}
if (csync_unix_extensions(ctx) < 0) {
CSYNC_LOG(CSYNC_LOG_PRIORITY_FATAL, "Could not detect filesystem type.");
rc = -1;
goto out;
if (csync_unix_extensions(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) {
@ -365,24 +368,25 @@ int csync_update(CSYNC *ctx) {
}
/* update detection for remote replica */
csync_gettime(&start);
ctx->current = REMOTE_REPLCIA;
ctx->replica = ctx->remote.type;
if( ! ctx->options.local_only_mode ) {
csync_gettime(&start);
ctx->current = REMOTE_REPLCIA;
ctx->replica = ctx->remote.type;
rc = csync_ftw(ctx, ctx->remote.uri, csync_walker, MAX_DEPTH);
rc = csync_ftw(ctx, ctx->remote.uri, csync_walker, MAX_DEPTH);
csync_gettime(&finish);
csync_gettime(&finish);
CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG,
"Update detection for remote replica took %.2f seconds "
"walking %zu files.",
c_secdiff(finish, start), c_rbtree_size(ctx->remote.tree));
csync_memstat_check();
CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG,
"Update detection for remote replica took %.2f seconds "
"walking %zu files.",
c_secdiff(finish, start), c_rbtree_size(ctx->remote.tree));
csync_memstat_check();
if (rc < 0) {
return -1;
if (rc < 0) {
return -1;
}
}
ctx->status |= CSYNC_STATUS_UPDATE;
return 0;
@ -734,4 +738,27 @@ int csync_enable_conflictcopys(CSYNC* ctx){
return 0;
}
int csync_set_local_only( CSYNC *ctx, bool local_only ) {
if (ctx == NULL) {
return -1;
}
if (ctx->status & CSYNC_STATUS_INIT) {
fprintf(stderr, "This function must be called before initialization.");
return -1;
}
ctx->options.local_only_mode=local_only;
return 0;
}
bool csync_get_local_only( CSYNC *ctx ) {
if (ctx == NULL) {
return -1;
}
return ctx->options.local_only_mode;
}
/* vim: set ts=8 sw=2 et cindent: */

View file

@ -31,6 +31,8 @@
#ifndef _CSYNC_H
#define _CSYNC_H
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
@ -283,6 +285,22 @@ const char *csync_get_statedb_file(CSYNC *ctx);
*/
int csync_enable_conflictcopys(CSYNC *ctx);
/**
* @brief Flag to tell csync that only a local run is intended. Call before csync_init
*
* @param local_only Bool flag to indicate local only mode.
*
* @return 0 on success, less than 0 if an error occured.
*/
int csync_set_local_only( CSYNC *ctx, bool local_only );
/**
* @brief Retrieve the flag to tell csync that only a local run is intended.
*
* @return 1: stay local only, 0: local and remote mode
*/
bool csync_get_local_only( CSYNC *ctx );
/* Used for special modes or debugging */
int csync_get_status(CSYNC *ctx);

View file

@ -117,6 +117,7 @@ struct csync_s {
int unix_extensions;
char *config_dir;
bool with_conflict_copys;
bool local_only_mode;
} options;
struct {