mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-22 13:05:51 +03:00
Use a struct for the journal.
This commit is contained in:
parent
69a4f9f1c1
commit
98962337c4
3 changed files with 19 additions and 15 deletions
|
@ -324,8 +324,8 @@ int csync_destroy(CSYNC *ctx) {
|
|||
|
||||
/* TODO: write journal */
|
||||
|
||||
if (ctx->journal) {
|
||||
sqlite3_close(ctx->journal);
|
||||
if (ctx->journal.db != NULL) {
|
||||
sqlite3_close(ctx->journal.db);
|
||||
/* TODO if we successfully synchronized, overwrite the original journal */
|
||||
}
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ static int csync_journal_check(const char *journal) {
|
|||
}
|
||||
|
||||
/* create database */
|
||||
if (sqlite3_open(journal, &db ) == SQLITE_OK) {
|
||||
if (sqlite3_open(journal, &db) == SQLITE_OK) {
|
||||
sqlite3_close(db);
|
||||
return 0;
|
||||
}
|
||||
|
@ -110,16 +110,16 @@ int csync_journal_load(CSYNC *ctx, const char *journal) {
|
|||
}
|
||||
|
||||
/* Open the temporary database */
|
||||
if (sqlite3_open(journal_tmp, &ctx->journal) != SQLITE_OK) {
|
||||
if (sqlite3_open(journal_tmp, &ctx->journal.db) != SQLITE_OK) {
|
||||
rc = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (csync_journal_is_empty(ctx)) {
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_NOTICE, "Journal doesn't exist");
|
||||
ctx->journal_exists = 0;
|
||||
ctx->journal.exists = 0;
|
||||
} else {
|
||||
ctx->journal_exists = 1;
|
||||
ctx->journal.exists = 1;
|
||||
}
|
||||
|
||||
out:
|
||||
|
@ -149,14 +149,14 @@ c_strlist_t *csync_journal_query(CSYNC *ctx, const char *statement) {
|
|||
usleep(100000);
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "sqlite3_prepare: BUSY counter: %d", busy_count);
|
||||
}
|
||||
err = sqlite3_prepare(ctx->journal, statement, -1, &stmt, &tail);
|
||||
err = sqlite3_prepare(ctx->journal.db, statement, -1, &stmt, &tail);
|
||||
} while (err == SQLITE_BUSY && busy_count ++ < 120);
|
||||
|
||||
if (err != SQLITE_OK) {
|
||||
if (err == SQLITE_BUSY) {
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR, "Gave up waiting for lock to clear");
|
||||
}
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_WARN, "sqlite3_compile error: %s - on query %s", sqlite3_errmsg(ctx->journal), statement);
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_WARN, "sqlite3_compile error: %s - on query %s", sqlite3_errmsg(ctx->journal.db), statement);
|
||||
result = c_strlist_new(1);
|
||||
break;
|
||||
} else {
|
||||
|
@ -205,7 +205,7 @@ c_strlist_t *csync_journal_query(CSYNC *ctx, const char *statement) {
|
|||
rc = sqlite3_finalize(stmt);
|
||||
|
||||
if (err != SQLITE_DONE && rc != SQLITE_SCHEMA) {
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR, "sqlite_step error: %s - on query: %s", sqlite3_errmsg(ctx->journal), statement);
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR, "sqlite_step error: %s - on query: %s", sqlite3_errmsg(ctx->journal.db), statement);
|
||||
result = c_strlist_new(1);
|
||||
}
|
||||
|
||||
|
@ -245,14 +245,14 @@ int csync_journal_insert(CSYNC *ctx, const char *statement) {
|
|||
usleep(100000);
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "sqlite3_prepare: BUSY counter: %d", busy_count);
|
||||
}
|
||||
err = sqlite3_prepare(ctx->journal, statement, -1, &stmt, &tail);
|
||||
err = sqlite3_prepare(ctx->journal.db, statement, -1, &stmt, &tail);
|
||||
} while (err == SQLITE_BUSY && busy_count++ < 120);
|
||||
|
||||
if (err != SQLITE_OK) {
|
||||
if (err == SQLITE_BUSY) {
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR, "Gave up waiting for lock to clear");
|
||||
}
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR, "sqlite3_compile error: %s on query %s", sqlite3_errmsg(ctx->journal), statement);
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR, "sqlite3_compile error: %s on query %s", sqlite3_errmsg(ctx->journal.db), statement);
|
||||
break;
|
||||
} else {
|
||||
busy_count = 0;
|
||||
|
@ -284,7 +284,7 @@ int csync_journal_insert(CSYNC *ctx, const char *statement) {
|
|||
rc = sqlite3_finalize(stmt);
|
||||
|
||||
if (err != SQLITE_DONE && rc != SQLITE_SCHEMA) {
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR, "sqlite_step error: %s on insert: %s", sqlite3_errmsg(ctx->journal), statement);
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR, "sqlite_step error: %s on insert: %s", sqlite3_errmsg(ctx->journal.db), statement);
|
||||
}
|
||||
|
||||
if (rc == SQLITE_SCHEMA) {
|
||||
|
@ -299,6 +299,6 @@ int csync_journal_insert(CSYNC *ctx, const char *statement) {
|
|||
}
|
||||
} while (rc == SQLITE_SCHEMA && retry_count < 10);
|
||||
|
||||
return sqlite3_last_insert_rowid(ctx->journal);
|
||||
return sqlite3_last_insert_rowid(ctx->journal.db);
|
||||
}
|
||||
|
||||
|
|
|
@ -68,7 +68,11 @@ enum csync_replica_e {
|
|||
*/
|
||||
struct csync_s {
|
||||
c_strlist_t *excludes;
|
||||
sqlite3 *journal;
|
||||
|
||||
struct {
|
||||
sqlite3 *db;
|
||||
int exists;
|
||||
} journal;
|
||||
|
||||
struct {
|
||||
char *uri;
|
||||
|
@ -97,7 +101,7 @@ struct csync_s {
|
|||
enum csync_replica_e current;
|
||||
enum csync_replica_e replica;
|
||||
|
||||
int journal_exists;
|
||||
int status;
|
||||
int initialized;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue