mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-28 03:40:11 +03:00
Load the statedb in csync_update rather than in csync_init.
This also allow to reduce duplicate code in csync_commit, and ease the error reporting of csync_commit csync_commit is supposed to be done after the previous sync, it is better to open the statedb before the sync
This commit is contained in:
parent
a42d942a35
commit
6ad2920809
2 changed files with 18 additions and 36 deletions
53
src/csync.c
53
src/csync.c
|
@ -240,22 +240,6 @@ int csync_init(CSYNC *ctx) {
|
|||
errbuf);
|
||||
}
|
||||
|
||||
/* create/load statedb */
|
||||
if (! csync_is_statedb_disabled(ctx)) {
|
||||
rc = asprintf(&ctx->statedb.file, "%s/.csync_journal.db",
|
||||
ctx->local.uri);
|
||||
if (rc < 0) {
|
||||
goto out;
|
||||
}
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "Journal: %s", ctx->statedb.file);
|
||||
|
||||
if (csync_statedb_load(ctx, ctx->statedb.file) < 0) {
|
||||
ctx->error_code = CSYNC_ERR_STATEDB_LOAD;
|
||||
rc = -1;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
ctx->local.type = LOCAL_REPLICA;
|
||||
|
||||
/* check for uri */
|
||||
|
@ -392,6 +376,23 @@ int csync_update(CSYNC *ctx) {
|
|||
}
|
||||
|
||||
SAFE_FREE(lock);
|
||||
|
||||
/* create/load statedb */
|
||||
if (! csync_is_statedb_disabled(ctx)) {
|
||||
rc = asprintf(&ctx->statedb.file, "%s/.csync_journal.db",
|
||||
ctx->local.uri);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "Journal: %s", ctx->statedb.file);
|
||||
|
||||
if (csync_statedb_load(ctx, ctx->statedb.file) < 0) {
|
||||
ctx->error_code = CSYNC_ERR_STATEDB_LOAD;
|
||||
rc = -1;
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
csync_memstat_check(ctx);
|
||||
|
||||
/* update detection for local replica */
|
||||
|
@ -820,26 +821,6 @@ int csync_commit(CSYNC *ctx) {
|
|||
|
||||
ctx->remote.read_from_db = 0;
|
||||
|
||||
/* create/load statedb */
|
||||
if (! csync_is_statedb_disabled(ctx)) {
|
||||
if(!ctx->statedb.file) {
|
||||
rc = asprintf(&ctx->statedb.file, "%s/.csync_journal.db",
|
||||
ctx->local.uri);
|
||||
if (rc < 0) {
|
||||
ctx->error_code = CSYNC_ERR_MEM;
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "Failed to assemble statedb file name.");
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "Journal: %s", ctx->statedb.file);
|
||||
|
||||
if (csync_statedb_load(ctx, ctx->statedb.file) < 0) {
|
||||
ctx->error_code = CSYNC_ERR_STATEDB_LOAD;
|
||||
rc = -1;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
/* Create new trees */
|
||||
if (c_rbtree_create(&ctx->local.tree, _key_cmp, _data_cmp) < 0) {
|
||||
ctx->error_code = CSYNC_ERR_TREE;
|
||||
|
|
|
@ -327,6 +327,7 @@ int csync_statedb_close(CSYNC *ctx, const char *statedb, int jwritten) {
|
|||
if( rc == SQLITE_BUSY ) {
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_NOTICE, "WARN: sqlite3_close got busy!");
|
||||
}
|
||||
ctx->statedb.db = NULL;
|
||||
|
||||
|
||||
if (asprintf(&statedb_tmp, "%s.ctmp", statedb) < 0) {
|
||||
|
|
Loading…
Reference in a new issue