Remove csync_s::replica
authorJocelyn Turcotte <jturcotte@woboq.com>
Mon, 4 Sep 2017 13:09:09 +0000 (15:09 +0200)
committerRoeland Jago Douma <roeland@famdouma.nl>
Thu, 5 Oct 2017 20:01:04 +0000 (22:01 +0200)
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.

src/csync/csync.cpp
src/csync/csync_private.h
src/csync/csync_update.cpp
src/csync/vio/csync_vio.cpp
test/csync/vio_tests/check_vio.cpp
test/csync/vio_tests/check_vio_ext.cpp

index aa531e18bc5e5a9dcd2399274caedcd571d2f5fa..0f028731daf5e277c86ecc3fa7fcfe5a1e2b9af4 100644 (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);
 
index aa1ead2ab87ec669a5635de099fed50ae14093b6..3d0c30b6e530d920eafbf78e48b31ede8ccb7ab1 100644 (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;
index fab7acd4a5d80e9d72e0b51c8d1ed5f455b0ddc8..d3cdfab894dd3b187531617eedd7376daffbeff9 100644 (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;
index cea6b04e1415eb9b8dbaf63910828b154cb6a943..57eb46c396635eb77114409aa074fcbae8a4cdb0 100644 (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);
index cdb36a6a0d47816388769287393a9ec1030f1e67..6f4f3a9b48aba55ecc2757bf1ef8a6e29b0909cf 100644 (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;
index d93bdef01e4ff45b801ca8aea9a8e565731cd139..faf5804e77f68c14491ef21b98c158b611c010c0 100644 (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;