Disable journal completely instead of writing and removing it.

This commit is contained in:
Andreas Schneider 2008-06-24 13:36:47 +02:00
parent d7309c4ff9
commit 8aed1cef83
3 changed files with 51 additions and 68 deletions

View file

@ -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;
}

View file

@ -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;

View file

@ -82,6 +82,7 @@ struct csync_s {
char *file;
sqlite3 *db;
int exists;
int disabled;
} journal;
struct {