Remove csync_s::replica

The only difference with csync_s::current is that it's
assigned the value of csync_s::local::type and
csync_s::remote::type, which never change. So might as
well only use the "current" field with constants.
This commit is contained in:
Jocelyn Turcotte 2017-09-04 15:09:09 +02:00
parent cb49635231
commit f6136dd036
6 changed files with 12 additions and 25 deletions

View file

@ -114,10 +114,6 @@ void csync_init(CSYNC *ctx, const char *db_file) {
assert(!(ctx->status & CSYNC_STATUS_INIT));
ctx->status_code = CSYNC_STATUS_OK;
ctx->local.type = LOCAL_REPLICA;
ctx->remote.type = REMOTE_REPLICA;
SAFE_FREE(ctx->statedb.file);
ctx->statedb.file = c_strdup(db_file);
@ -159,7 +155,6 @@ int csync_update(CSYNC *ctx) {
/* update detection for local replica */
csync_gettime(&start);
ctx->current = LOCAL_REPLICA;
ctx->replica = ctx->local.type;
rc = csync_ftw(ctx, ctx->local.uri, csync_walker, MAX_DEPTH);
if (rc < 0) {
@ -179,7 +174,6 @@ int csync_update(CSYNC *ctx) {
/* update detection for remote replica */
csync_gettime(&start);
ctx->current = REMOTE_REPLICA;
ctx->replica = ctx->remote.type;
rc = csync_ftw(ctx, "", csync_walker, MAX_DEPTH);
if (rc < 0) {
@ -225,7 +219,6 @@ int csync_reconcile(CSYNC *ctx) {
}
ctx->current = LOCAL_REPLICA;
ctx->replica = ctx->local.type;
rc = csync_reconcile_updates(ctx);
@ -246,7 +239,6 @@ int csync_reconcile(CSYNC *ctx) {
csync_gettime(&start);
ctx->current = REMOTE_REPLICA;
ctx->replica = ctx->remote.type;
rc = csync_reconcile_updates(ctx);

View file

@ -106,12 +106,10 @@ struct csync_s {
struct {
char *uri;
c_rbtree_t *tree;
enum csync_replica_e type;
} local;
struct {
c_rbtree_t *tree;
enum csync_replica_e type;
int read_from_db;
const char *root_perms; /* Permission of the root folder. (Since the root folder is not in the db tree, we need to keep a separate entry.) */
} remote;
@ -120,9 +118,6 @@ struct csync_s {
/* replica we are currently walking */
enum csync_replica_e current;
/* replica we want to work on */
enum csync_replica_e replica;
/* Used in the update phase so changes in the sub directories can be notified to
parent directories */
csync_file_stat_t *current_fs;

View file

@ -660,7 +660,7 @@ int csync_ftw(CSYNC *ctx, const char *uri, csync_walker_fn fn,
}
/* Only for the local replica we have to stat(), for the remote one we have all data already */
if (ctx->replica == LOCAL_REPLICA) {
if (ctx->current == LOCAL_REPLICA) {
res = csync_vio_stat(ctx, filename, dirent.get());
} else {
res = 0;

View file

@ -38,7 +38,7 @@
#include "csync_log.h"
csync_vio_handle_t *csync_vio_opendir(CSYNC *ctx, const char *name) {
switch(ctx->replica) {
switch(ctx->current) {
case REMOTE_REPLICA:
if(ctx->remote.read_from_db) {
CSYNC_LOG(CSYNC_LOG_PRIORITY_WARN, "Read from db flag is true, should not!" );
@ -47,12 +47,12 @@ csync_vio_handle_t *csync_vio_opendir(CSYNC *ctx, const char *name) {
break;
case LOCAL_REPLICA:
if( ctx->callbacks.update_callback ) {
ctx->callbacks.update_callback(ctx->replica, name, ctx->callbacks.update_callback_userdata);
ctx->callbacks.update_callback(ctx->current, name, ctx->callbacks.update_callback_userdata);
}
return csync_vio_local_opendir(name);
break;
default:
CSYNC_LOG(CSYNC_LOG_PRIORITY_ALERT, "Invalid replica (%d)", (int)ctx->replica);
CSYNC_LOG(CSYNC_LOG_PRIORITY_ALERT, "Invalid replica (%d)", (int)ctx->current);
break;
}
return NULL;
@ -66,7 +66,7 @@ int csync_vio_closedir(CSYNC *ctx, csync_vio_handle_t *dhandle) {
return -1;
}
switch(ctx->replica) {
switch(ctx->current) {
case REMOTE_REPLICA:
if( ctx->remote.read_from_db ) {
CSYNC_LOG(CSYNC_LOG_PRIORITY_WARN, "Remote ReadFromDb is true, should not!");
@ -78,14 +78,14 @@ int csync_vio_closedir(CSYNC *ctx, csync_vio_handle_t *dhandle) {
rc = csync_vio_local_closedir(dhandle);
break;
default:
CSYNC_LOG(CSYNC_LOG_PRIORITY_ALERT, "Invalid replica (%d)", (int)ctx->replica);
CSYNC_LOG(CSYNC_LOG_PRIORITY_ALERT, "Invalid replica (%d)", (int)ctx->current);
break;
}
return rc;
}
std::unique_ptr<csync_file_stat_t> csync_vio_readdir(CSYNC *ctx, csync_vio_handle_t *dhandle) {
switch(ctx->replica) {
switch(ctx->current) {
case REMOTE_REPLICA:
if( ctx->remote.read_from_db ) {
CSYNC_LOG(CSYNC_LOG_PRIORITY_WARN, "Remote readfromdb is true, should not!");
@ -96,7 +96,7 @@ std::unique_ptr<csync_file_stat_t> csync_vio_readdir(CSYNC *ctx, csync_vio_handl
return csync_vio_local_readdir(dhandle);
break;
default:
CSYNC_LOG(CSYNC_LOG_PRIORITY_ALERT, "Invalid replica (%d)", (int)ctx->replica);
CSYNC_LOG(CSYNC_LOG_PRIORITY_ALERT, "Invalid replica (%d)", (int)ctx->current);
break;
}
@ -107,10 +107,10 @@ std::unique_ptr<csync_file_stat_t> csync_vio_readdir(CSYNC *ctx, csync_vio_handl
int csync_vio_stat(CSYNC *ctx, const char *uri, csync_file_stat_t *buf) {
int rc = -1;
switch(ctx->replica) {
switch(ctx->current) {
case REMOTE_REPLICA:
CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR, "ERROR: Cannot call remote stat, not implemented");
assert(ctx->replica != REMOTE_REPLICA);
assert(ctx->current != REMOTE_REPLICA);
break;
case LOCAL_REPLICA:
rc = csync_vio_local_stat(uri, buf);

View file

@ -51,7 +51,7 @@ static int setup(void **state)
csync_create(&csync, "/tmp/csync1");
csync->replica = LOCAL_REPLICA;
csync->current = LOCAL_REPLICA;
*state = csync;
return 0;

View file

@ -99,7 +99,7 @@ static int setup_testenv(void **state) {
csync_create(&(mystate->csync), "/tmp/csync1");
mystate->csync->replica = LOCAL_REPLICA;
mystate->csync->current = LOCAL_REPLICA;
*state = mystate;
return 0;