mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-26 15:06:08 +03:00
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:
parent
cb49635231
commit
f6136dd036
6 changed files with 12 additions and 25 deletions
|
@ -114,10 +114,6 @@ void csync_init(CSYNC *ctx, const char *db_file) {
|
||||||
assert(!(ctx->status & CSYNC_STATUS_INIT));
|
assert(!(ctx->status & CSYNC_STATUS_INIT));
|
||||||
ctx->status_code = CSYNC_STATUS_OK;
|
ctx->status_code = CSYNC_STATUS_OK;
|
||||||
|
|
||||||
ctx->local.type = LOCAL_REPLICA;
|
|
||||||
|
|
||||||
ctx->remote.type = REMOTE_REPLICA;
|
|
||||||
|
|
||||||
SAFE_FREE(ctx->statedb.file);
|
SAFE_FREE(ctx->statedb.file);
|
||||||
ctx->statedb.file = c_strdup(db_file);
|
ctx->statedb.file = c_strdup(db_file);
|
||||||
|
|
||||||
|
@ -159,7 +155,6 @@ int csync_update(CSYNC *ctx) {
|
||||||
/* update detection for local replica */
|
/* update detection for local replica */
|
||||||
csync_gettime(&start);
|
csync_gettime(&start);
|
||||||
ctx->current = LOCAL_REPLICA;
|
ctx->current = LOCAL_REPLICA;
|
||||||
ctx->replica = ctx->local.type;
|
|
||||||
|
|
||||||
rc = csync_ftw(ctx, ctx->local.uri, csync_walker, MAX_DEPTH);
|
rc = csync_ftw(ctx, ctx->local.uri, csync_walker, MAX_DEPTH);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
|
@ -179,7 +174,6 @@ int csync_update(CSYNC *ctx) {
|
||||||
/* update detection for remote replica */
|
/* update detection for remote replica */
|
||||||
csync_gettime(&start);
|
csync_gettime(&start);
|
||||||
ctx->current = REMOTE_REPLICA;
|
ctx->current = REMOTE_REPLICA;
|
||||||
ctx->replica = ctx->remote.type;
|
|
||||||
|
|
||||||
rc = csync_ftw(ctx, "", csync_walker, MAX_DEPTH);
|
rc = csync_ftw(ctx, "", csync_walker, MAX_DEPTH);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
|
@ -225,7 +219,6 @@ int csync_reconcile(CSYNC *ctx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->current = LOCAL_REPLICA;
|
ctx->current = LOCAL_REPLICA;
|
||||||
ctx->replica = ctx->local.type;
|
|
||||||
|
|
||||||
rc = csync_reconcile_updates(ctx);
|
rc = csync_reconcile_updates(ctx);
|
||||||
|
|
||||||
|
@ -246,7 +239,6 @@ int csync_reconcile(CSYNC *ctx) {
|
||||||
csync_gettime(&start);
|
csync_gettime(&start);
|
||||||
|
|
||||||
ctx->current = REMOTE_REPLICA;
|
ctx->current = REMOTE_REPLICA;
|
||||||
ctx->replica = ctx->remote.type;
|
|
||||||
|
|
||||||
rc = csync_reconcile_updates(ctx);
|
rc = csync_reconcile_updates(ctx);
|
||||||
|
|
||||||
|
|
|
@ -106,12 +106,10 @@ struct csync_s {
|
||||||
struct {
|
struct {
|
||||||
char *uri;
|
char *uri;
|
||||||
c_rbtree_t *tree;
|
c_rbtree_t *tree;
|
||||||
enum csync_replica_e type;
|
|
||||||
} local;
|
} local;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
c_rbtree_t *tree;
|
c_rbtree_t *tree;
|
||||||
enum csync_replica_e type;
|
|
||||||
int read_from_db;
|
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.) */
|
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;
|
} remote;
|
||||||
|
@ -120,9 +118,6 @@ struct csync_s {
|
||||||
/* replica we are currently walking */
|
/* replica we are currently walking */
|
||||||
enum csync_replica_e current;
|
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
|
/* Used in the update phase so changes in the sub directories can be notified to
|
||||||
parent directories */
|
parent directories */
|
||||||
csync_file_stat_t *current_fs;
|
csync_file_stat_t *current_fs;
|
||||||
|
|
|
@ -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 */
|
/* 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());
|
res = csync_vio_stat(ctx, filename, dirent.get());
|
||||||
} else {
|
} else {
|
||||||
res = 0;
|
res = 0;
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
#include "csync_log.h"
|
#include "csync_log.h"
|
||||||
|
|
||||||
csync_vio_handle_t *csync_vio_opendir(CSYNC *ctx, const char *name) {
|
csync_vio_handle_t *csync_vio_opendir(CSYNC *ctx, const char *name) {
|
||||||
switch(ctx->replica) {
|
switch(ctx->current) {
|
||||||
case REMOTE_REPLICA:
|
case REMOTE_REPLICA:
|
||||||
if(ctx->remote.read_from_db) {
|
if(ctx->remote.read_from_db) {
|
||||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_WARN, "Read from db flag is true, should not!" );
|
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;
|
break;
|
||||||
case LOCAL_REPLICA:
|
case LOCAL_REPLICA:
|
||||||
if( ctx->callbacks.update_callback ) {
|
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);
|
return csync_vio_local_opendir(name);
|
||||||
break;
|
break;
|
||||||
default:
|
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;
|
break;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -66,7 +66,7 @@ int csync_vio_closedir(CSYNC *ctx, csync_vio_handle_t *dhandle) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(ctx->replica) {
|
switch(ctx->current) {
|
||||||
case REMOTE_REPLICA:
|
case REMOTE_REPLICA:
|
||||||
if( ctx->remote.read_from_db ) {
|
if( ctx->remote.read_from_db ) {
|
||||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_WARN, "Remote ReadFromDb is true, should not!");
|
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);
|
rc = csync_vio_local_closedir(dhandle);
|
||||||
break;
|
break;
|
||||||
default:
|
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;
|
break;
|
||||||
}
|
}
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<csync_file_stat_t> csync_vio_readdir(CSYNC *ctx, csync_vio_handle_t *dhandle) {
|
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:
|
case REMOTE_REPLICA:
|
||||||
if( ctx->remote.read_from_db ) {
|
if( ctx->remote.read_from_db ) {
|
||||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_WARN, "Remote readfromdb is true, should not!");
|
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);
|
return csync_vio_local_readdir(dhandle);
|
||||||
break;
|
break;
|
||||||
default:
|
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;
|
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 csync_vio_stat(CSYNC *ctx, const char *uri, csync_file_stat_t *buf) {
|
||||||
int rc = -1;
|
int rc = -1;
|
||||||
|
|
||||||
switch(ctx->replica) {
|
switch(ctx->current) {
|
||||||
case REMOTE_REPLICA:
|
case REMOTE_REPLICA:
|
||||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR, "ERROR: Cannot call remote stat, not implemented");
|
CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR, "ERROR: Cannot call remote stat, not implemented");
|
||||||
assert(ctx->replica != REMOTE_REPLICA);
|
assert(ctx->current != REMOTE_REPLICA);
|
||||||
break;
|
break;
|
||||||
case LOCAL_REPLICA:
|
case LOCAL_REPLICA:
|
||||||
rc = csync_vio_local_stat(uri, buf);
|
rc = csync_vio_local_stat(uri, buf);
|
||||||
|
|
|
@ -51,7 +51,7 @@ static int setup(void **state)
|
||||||
|
|
||||||
csync_create(&csync, "/tmp/csync1");
|
csync_create(&csync, "/tmp/csync1");
|
||||||
|
|
||||||
csync->replica = LOCAL_REPLICA;
|
csync->current = LOCAL_REPLICA;
|
||||||
|
|
||||||
*state = csync;
|
*state = csync;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -99,7 +99,7 @@ static int setup_testenv(void **state) {
|
||||||
|
|
||||||
csync_create(&(mystate->csync), "/tmp/csync1");
|
csync_create(&(mystate->csync), "/tmp/csync1");
|
||||||
|
|
||||||
mystate->csync->replica = LOCAL_REPLICA;
|
mystate->csync->current = LOCAL_REPLICA;
|
||||||
|
|
||||||
*state = mystate;
|
*state = mystate;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in a new issue