From 8aed1cef83bfa549085fc1fefa4e5ec6c4283097 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 24 Jun 2008 13:36:47 +0200 Subject: [PATCH] Disable journal completely instead of writing and removing it. --- client/csync_client.c | 44 ++++++++++--------------- src/csync.c | 74 +++++++++++++++++++------------------------ src/csync_private.h | 1 + 3 files changed, 51 insertions(+), 68 deletions(-) diff --git a/client/csync_client.c b/client/csync_client.c index 478864d583..045a8d4dc2 100644 --- a/client/csync_client.c +++ b/client/csync_client.c @@ -33,7 +33,7 @@ enum { KEY_DUMMY = 129, KEY_EXCLUDE_FILE, - KEY_REMOVE_JOURNAL, + KEY_DISABLE_JOURNAL, }; const char *argp_program_version = "csync commandline client 0.42"; @@ -48,11 +48,11 @@ static char args_doc[] = "SOURCE DESTINATION"; /* The options we understand. */ static struct argp_option options[] = { { - .name = "remove-journal", - .key = KEY_REMOVE_JOURNAL, + .name = "disable-journal", + .key = KEY_DISABLE_JOURNAL, .arg = NULL, .flags = 0, - .doc = "Remove the journal after synchronization.", + .doc = "Disable the usage and creation of a journal.", .group = 0 }, { @@ -72,7 +72,7 @@ static struct argp_option options[] = { .group = 0 }, { - .name = "journal", + .name = "create-journal", .key = 'j', .arg = NULL, .flags = 0, @@ -94,8 +94,8 @@ static struct argp_option options[] = { struct argument_s { char *args[2]; /* SOURCE and DESTINATION */ char *exclude_file; - int journal_remove; - int journal_create; + int disable_journal; + int create_journal; int update; int reconcile; int propagate; @@ -110,19 +110,19 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state) { switch (key) { case 'j': - arguments->journal_create = 1; + arguments->create_journal = 1; arguments->update = 1; arguments->reconcile = 0; arguments->propagate = 0; break; case 'u': - arguments->journal_create = 0; + arguments->create_journal = 0; arguments->update = 1; arguments->reconcile = 0; arguments->propagate = 0; break; case 'r': - arguments->journal_create = 0; + arguments->create_journal = 0; arguments->update = 1; arguments->reconcile = 1; arguments->propagate = 0; @@ -130,8 +130,8 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state) { case KEY_EXCLUDE_FILE: arguments->exclude_file = strdup(arg); break; - case KEY_REMOVE_JOURNAL: - arguments->journal_remove = 1; + case KEY_DISABLE_JOURNAL: + arguments->disable_journal = 1; break; case ARGP_KEY_ARG: if (state->arg_num >= 2) { @@ -177,15 +177,14 @@ static struct argp argp = {options, parse_opt, args_doc, doc, NULL, NULL, NULL}; int main(int argc, char **argv) { int rc = 0; - char *journal = NULL; CSYNC *csync; struct argument_s arguments; /* Default values. */ arguments.exclude_file = NULL; - arguments.journal_remove = 0; - arguments.journal_create = 0; + arguments.disable_journal = 0; + arguments.create_journal = 0; arguments.update = 1; arguments.reconcile = 1; arguments.propagate = 1; @@ -201,8 +200,8 @@ int main(int argc, char **argv) { exit(1); } - csync_set_module_auth_callback(csync, csync_auth_fn); - fprintf(stdout,"\n"); + csync_set_auth_callback(csync, csync_auth_fn); + csync_disable_journal(csync); if (csync_init(csync) < 0) { perror("csync_init"); @@ -219,10 +218,6 @@ int main(int argc, char **argv) { } } - if (arguments.journal_remove) { - journal = csync_get_journal_file(csync); - } - if (arguments.update) { if (csync_update(csync) < 0) { perror("csync_update"); @@ -247,18 +242,13 @@ int main(int argc, char **argv) { } } - if (arguments.journal_create) { + if (arguments.create_journal) { csync_set_status(csync, 0xFFFF); } out: csync_destroy(csync); - if (arguments.journal_remove && journal != NULL) { - unlink(journal); - free(journal); - } - return rc; } diff --git a/src/csync.c b/src/csync.c index 14748cd602..c46f169d57 100644 --- a/src/csync.c +++ b/src/csync.c @@ -210,17 +210,19 @@ int csync_init(CSYNC *ctx) { } /* create/load journal */ - if (asprintf(&ctx->journal.file, "%s/csync_journal_%lu.db", ctx->options.config_dir, - c_jhash64((uint8_t *) ctx->remote.uri, strlen(ctx->remote.uri), 0)) < 0) { - rc = -1; - goto out; - } - CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "Remote replica: %s", ctx->remote.uri); - CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "Journal file: %s", ctx->journal.file); + if (! csync_is_journal_disabled(ctx)) { + if (asprintf(&ctx->journal.file, "%s/csync_journal_%lu.db", ctx->options.config_dir, + c_jhash64((uint8_t *) ctx->remote.uri, strlen(ctx->remote.uri), 0)) < 0) { + rc = -1; + goto out; + } + CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "Remote replica: %s", ctx->remote.uri); + CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "Journal file: %s", ctx->journal.file); - if (csync_journal_load(ctx, ctx->journal.file) < 0) { - rc = -1; - goto out; + if (csync_journal_load(ctx, ctx->journal.file) < 0) { + rc = -1; + goto out; + } } ctx->local.type = LOCAL_REPLICA; @@ -553,44 +555,34 @@ int csync_set_config_dir(CSYNC *ctx, const char *path) { return 0; } -int csync_remove_config_dir(CSYNC *ctx) { - char *path = NULL; - - if (asprintf(&path, "%s/%s", ctx->options.config_dir, CSYNC_LOG_FILE) < 0) { +int csync_enable_journal(CSYNC *ctx) { + if (ctx == NULL) { return -1; } - unlink(path); - SAFE_FREE(path); - if (asprintf(&path, "%s/%s", ctx->options.config_dir, CSYNC_CONF_FILE) < 0) { - return -1; - } - unlink(path); - SAFE_FREE(path); - - if (asprintf(&path, "%s/%s", ctx->options.config_dir, CSYNC_CONF_FILE) < 0) { - return -1; - } - unlink(path); - SAFE_FREE(path); - - if (asprintf(&path, "%s", ctx->journal.file) < 0) { - return -1; - } - unlink(path); - SAFE_FREE(path); - - if (asprintf(&path, "%s.ctmp", ctx->journal.file) < 0) { - return -1; - } - unlink(path); - SAFE_FREE(path); - - unlink(ctx->options.config_dir); + ctx->journal.disabled = 0; return 0; } +int csync_disable_journal(CSYNC *ctx) { + if (ctx == NULL) { + return -1; + } + + ctx->journal.disabled = 1; + + return 0; +} + +int csync_is_journal_disabled(CSYNC *ctx) { + if (ctx == NULL) { + return -1; + } + + return ctx->journal.disabled; +} + int csync_set_auth_callback(CSYNC *ctx, csync_auth_callback cb) { if (ctx == NULL || cb == NULL) { return -1; diff --git a/src/csync_private.h b/src/csync_private.h index 9c30d982fe..8bc01a4f08 100644 --- a/src/csync_private.h +++ b/src/csync_private.h @@ -82,6 +82,7 @@ struct csync_s { char *file; sqlite3 *db; int exists; + int disabled; } journal; struct {