From 98962337c4c0ff88e0e8acc681973f29d36b4f31 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 29 Apr 2008 09:23:51 +0200 Subject: [PATCH] Use a struct for the journal. --- src/csync.c | 4 ++-- src/csync_journal.c | 22 +++++++++++----------- src/csync_private.h | 8 ++++++-- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/csync.c b/src/csync.c index a70510480..ec2c80276 100644 --- a/src/csync.c +++ b/src/csync.c @@ -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 */ } diff --git a/src/csync_journal.c b/src/csync_journal.c index 54a743b72..4941643a9 100644 --- a/src/csync_journal.c +++ b/src/csync_journal.c @@ -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); } diff --git a/src/csync_private.h b/src/csync_private.h index 751ff18b1..786cde828 100644 --- a/src/csync_private.h +++ b/src/csync_private.h @@ -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; };