зеркало из https://github.com/nextcloud/desktop.git
Rename journal functions to statedb.
This commit is contained in:
Родитель
88690312d7
Коммит
e5286c7c8a
|
@ -33,7 +33,7 @@
|
|||
enum {
|
||||
KEY_DUMMY = 129,
|
||||
KEY_EXCLUDE_FILE,
|
||||
KEY_CREATE_JOURNAL,
|
||||
KEY_CREATE_STATEDB,
|
||||
};
|
||||
|
||||
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 = "disable-journal",
|
||||
.name = "disable-statedb",
|
||||
.key = 'd',
|
||||
.arg = NULL,
|
||||
.flags = 0,
|
||||
.doc = "Disable the usage and creation of a journal.",
|
||||
.doc = "Disable the usage and creation of a statedb.",
|
||||
.group = 0
|
||||
},
|
||||
{
|
||||
|
@ -72,11 +72,11 @@ static struct argp_option options[] = {
|
|||
.group = 0
|
||||
},
|
||||
{
|
||||
.name = "create-journal",
|
||||
.key = KEY_CREATE_JOURNAL,
|
||||
.name = "create-statedb",
|
||||
.key = KEY_CREATE_STATEDB,
|
||||
.arg = NULL,
|
||||
.flags = 0,
|
||||
.doc = "Run update detection and write the journal (TESTING ONLY!)",
|
||||
.doc = "Run update detection and write the statedb (TESTING ONLY!)",
|
||||
.group = 0
|
||||
},
|
||||
{
|
||||
|
@ -94,8 +94,8 @@ static struct argp_option options[] = {
|
|||
struct argument_s {
|
||||
char *args[2]; /* SOURCE and DESTINATION */
|
||||
char *exclude_file;
|
||||
int disable_journal;
|
||||
int create_journal;
|
||||
int disable_statedb;
|
||||
int create_statedb;
|
||||
int update;
|
||||
int reconcile;
|
||||
int propagate;
|
||||
|
@ -110,13 +110,13 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state) {
|
|||
|
||||
switch (key) {
|
||||
case 'u':
|
||||
arguments->create_journal = 0;
|
||||
arguments->create_statedb = 0;
|
||||
arguments->update = 1;
|
||||
arguments->reconcile = 0;
|
||||
arguments->propagate = 0;
|
||||
break;
|
||||
case 'r':
|
||||
arguments->create_journal = 0;
|
||||
arguments->create_statedb = 0;
|
||||
arguments->update = 1;
|
||||
arguments->reconcile = 1;
|
||||
arguments->propagate = 0;
|
||||
|
@ -125,10 +125,10 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state) {
|
|||
arguments->exclude_file = strdup(arg);
|
||||
break;
|
||||
case 'd':
|
||||
arguments->disable_journal = 1;
|
||||
arguments->disable_statedb = 1;
|
||||
break;
|
||||
case KEY_CREATE_JOURNAL:
|
||||
arguments->create_journal = 1;
|
||||
case KEY_CREATE_STATEDB:
|
||||
arguments->create_statedb = 1;
|
||||
arguments->update = 1;
|
||||
arguments->reconcile = 0;
|
||||
arguments->propagate = 0;
|
||||
|
@ -183,8 +183,8 @@ int main(int argc, char **argv) {
|
|||
|
||||
/* Default values. */
|
||||
arguments.exclude_file = NULL;
|
||||
arguments.disable_journal = 0;
|
||||
arguments.create_journal = 0;
|
||||
arguments.disable_statedb = 0;
|
||||
arguments.create_statedb = 0;
|
||||
arguments.update = 1;
|
||||
arguments.reconcile = 1;
|
||||
arguments.propagate = 1;
|
||||
|
@ -201,8 +201,8 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
|
||||
csync_set_auth_callback(csync, csync_auth_fn);
|
||||
if (arguments.disable_journal) {
|
||||
csync_disable_journal(csync);
|
||||
if (arguments.disable_statedb) {
|
||||
csync_disable_statedb(csync);
|
||||
}
|
||||
|
||||
if (csync_init(csync) < 0) {
|
||||
|
@ -244,7 +244,7 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
}
|
||||
|
||||
if (arguments.create_journal) {
|
||||
if (arguments.create_statedb) {
|
||||
csync_set_status(csync, 0xFFFF);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
<category name="root" priority="none"/>
|
||||
<category name="csync.api" priority="notice" appender="stderr"/>
|
||||
<category name="csync.config" priority="notice" appender="stderr"/>
|
||||
<category name="csync.journal" priority="notice" appender="stderr"/>
|
||||
<category name="csync.statedb" priority="notice" appender="stderr"/>
|
||||
<category name="csync.lock" priority="notice" appender="stderr"/>
|
||||
<category name="csync.time" priority="notice" appender="stderr"/>
|
||||
<category name="csync.util" priority="notice" appender="stderr"/>
|
||||
|
|
12
doc/csync.1
12
doc/csync.1
|
@ -1,11 +1,11 @@
|
|||
.\" Title: csync
|
||||
.\" Author:
|
||||
.\" Generator: DocBook XSL Stylesheets v1.73.2 <http://docbook.sf.net/>
|
||||
.\" Date: 07/03/2008
|
||||
.\" Date: 07/09/2008
|
||||
.\" Manual:
|
||||
.\" Source:
|
||||
.\"
|
||||
.TH "CSYNC" "1" "07/03/2008" "" ""
|
||||
.TH "CSYNC" "1" "07/09/2008" "" ""
|
||||
.\" disable hyphenation
|
||||
.nh
|
||||
.\" disable justification (adjust text to left margin only)
|
||||
|
@ -22,14 +22,14 @@ You can use csync for different things\. The intention is to provide Roaming Hom
|
|||
.sp
|
||||
.SH "OPTIONS"
|
||||
.PP
|
||||
\fB\-\-create\-journal\fR
|
||||
\fB\-\-create\-statedb\fR
|
||||
.RS 4
|
||||
Run update detection and write the journal (TESTING ONLY!)
|
||||
Run update detection and write the statedb (TESTING ONLY!)
|
||||
.RE
|
||||
.PP
|
||||
\fB\-d, \-\-disable\-journal\fR
|
||||
\fB\-d, \-\-disable\-statedb\fR
|
||||
.RS 4
|
||||
Disable the usage and creation of a journal\.
|
||||
Disable the usage and creation of a statedb\.
|
||||
.RE
|
||||
.PP
|
||||
\fB\-\-exclude\-file=\fR\fB\fI<file>\fR\fR
|
||||
|
|
|
@ -29,11 +29,11 @@ collection or create a backup of a directory.
|
|||
OPTIONS
|
||||
-------
|
||||
|
||||
*--create-journal*::
|
||||
Run update detection and write the journal
|
||||
*--create-statedb*::
|
||||
Run update detection and write the statedb
|
||||
(TESTING ONLY!)
|
||||
*-d, --disable-journal*::
|
||||
Disable the usage and creation of a journal.
|
||||
*-d, --disable-statedb*::
|
||||
Disable the usage and creation of a statedb.
|
||||
|
||||
*--exclude-file='<file>'*::
|
||||
Add an additional exclude file
|
||||
|
|
42
src/csync.c
42
src/csync.c
|
@ -209,18 +209,18 @@ int csync_init(CSYNC *ctx) {
|
|||
CSYNC_LOG(CSYNC_LOG_PRIORITY_INFO, "Could not load %s - %s", exclude, strerror(errno));
|
||||
}
|
||||
|
||||
/* create/load journal */
|
||||
if (! csync_is_journal_disabled(ctx)) {
|
||||
/* create/load statedb */
|
||||
if (! csync_is_statedb_disabled(ctx)) {
|
||||
uint64_t h = c_jhash64((uint8_t *) ctx->remote.uri, strlen(ctx->remote.uri), 0);
|
||||
if (asprintf(&ctx->journal.file, "%s/csync_journal_%llu.db",
|
||||
if (asprintf(&ctx->statedb.file, "%s/csync_statedb_%llu.db",
|
||||
ctx->options.config_dir, (long long unsigned int) h) < 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);
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "Statedb: %s", ctx->statedb.file);
|
||||
|
||||
if (csync_journal_load(ctx, ctx->journal.file) < 0) {
|
||||
if (csync_statedb_load(ctx, ctx->statedb.file) < 0) {
|
||||
rc = -1;
|
||||
goto out;
|
||||
}
|
||||
|
@ -459,8 +459,8 @@ int csync_destroy(CSYNC *ctx) {
|
|||
|
||||
csync_vio_shutdown(ctx);
|
||||
|
||||
/* if we have a journal */
|
||||
if (ctx->journal.db != NULL) {
|
||||
/* if we have a statedb */
|
||||
if (ctx->statedb.db != NULL) {
|
||||
/* and we have successfully synchronized */
|
||||
if (ctx->status >= CSYNC_STATUS_DONE) {
|
||||
/* merge trees */
|
||||
|
@ -469,20 +469,20 @@ int csync_destroy(CSYNC *ctx) {
|
|||
strerror(errno));
|
||||
} else {
|
||||
clock_gettime(CLOCK_REALTIME, &start);
|
||||
/* write the journal to disk */
|
||||
if (csync_journal_write(ctx) == 0) {
|
||||
/* write the statedb to disk */
|
||||
if (csync_statedb_write(ctx) == 0) {
|
||||
jwritten = 1;
|
||||
clock_gettime(CLOCK_REALTIME, &finish);
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG,
|
||||
"Writing the journal of %zu files to disk took %.2f seconds",
|
||||
"Writing the statedb of %zu files to disk took %.2f seconds",
|
||||
c_rbtree_size(ctx->local.tree), c_secdiff(finish, start));
|
||||
} else {
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR, "Unable to write journal: %s",
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR, "Unable to write statedb: %s",
|
||||
strerror(errno));
|
||||
}
|
||||
}
|
||||
}
|
||||
csync_journal_close(ctx, ctx->journal.file, jwritten);
|
||||
csync_statedb_close(ctx, ctx->statedb.file, jwritten);
|
||||
}
|
||||
|
||||
/* clear exclude list */
|
||||
|
@ -513,7 +513,7 @@ int csync_destroy(CSYNC *ctx) {
|
|||
SAFE_FREE(ctx->local.uri);
|
||||
SAFE_FREE(ctx->remote.uri);
|
||||
SAFE_FREE(ctx->options.config_dir);
|
||||
SAFE_FREE(ctx->journal.file);
|
||||
SAFE_FREE(ctx->statedb.file);
|
||||
|
||||
SAFE_FREE(ctx);
|
||||
|
||||
|
@ -556,7 +556,7 @@ int csync_set_config_dir(CSYNC *ctx, const char *path) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int csync_enable_journal(CSYNC *ctx) {
|
||||
int csync_enable_statedb(CSYNC *ctx) {
|
||||
if (ctx == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -566,12 +566,12 @@ int csync_enable_journal(CSYNC *ctx) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
ctx->journal.disabled = 0;
|
||||
ctx->statedb.disabled = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int csync_disable_journal(CSYNC *ctx) {
|
||||
int csync_disable_statedb(CSYNC *ctx) {
|
||||
if (ctx == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -581,17 +581,17 @@ int csync_disable_journal(CSYNC *ctx) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
ctx->journal.disabled = 1;
|
||||
ctx->statedb.disabled = 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int csync_is_journal_disabled(CSYNC *ctx) {
|
||||
int csync_is_statedb_disabled(CSYNC *ctx) {
|
||||
if (ctx == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ctx->journal.disabled;
|
||||
return ctx->statedb.disabled;
|
||||
}
|
||||
|
||||
int csync_set_auth_callback(CSYNC *ctx, csync_auth_callback cb) {
|
||||
|
@ -609,12 +609,12 @@ int csync_set_auth_callback(CSYNC *ctx, csync_auth_callback cb) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
char *csync_get_journal_file(CSYNC *ctx) {
|
||||
char *csync_get_statedb_file(CSYNC *ctx) {
|
||||
if (ctx == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return c_strdup(ctx->journal.file);
|
||||
return c_strdup(ctx->statedb.file);
|
||||
}
|
||||
|
||||
csync_auth_callback csync_get_auth_callback(CSYNC *ctx) {
|
||||
|
|
13
src/csync.h
13
src/csync.h
|
@ -52,7 +52,6 @@ extern "C" {
|
|||
#define CSYNC_CONF_FILE "csync.conf"
|
||||
#define CSYNC_LOG_FILE "csync_log.conf"
|
||||
#define CSYNC_EXCLUDE_FILE "csync_exclude.conf"
|
||||
#define CSYNC_JOURNAL_FILE "csync_journal.db"
|
||||
#define CSYNC_LOCK_FILE "lock"
|
||||
|
||||
typedef void (*csync_auth_callback) (char *usr, size_t usrlen, char *pwd, size_t pwlen);
|
||||
|
@ -74,7 +73,7 @@ int csync_create(CSYNC **csync, const char *local, const char *remote);
|
|||
/**
|
||||
* @brief Initialize the file synchronizer.
|
||||
*
|
||||
* This function loads the configuration, the journal and locks the client.
|
||||
* This function loads the configuration, the statedb and locks the client.
|
||||
*
|
||||
* @param ctx The context to initialize.
|
||||
*
|
||||
|
@ -112,7 +111,7 @@ int csync_propagate(CSYNC *ctx);
|
|||
/**
|
||||
* @brief Destroy the csync context
|
||||
*
|
||||
* Writes the journal, unlocks csync and frees the memory.
|
||||
* Writes the statedb, unlocks csync and frees the memory.
|
||||
*
|
||||
* @param ctx The context to destroy.
|
||||
*
|
||||
|
@ -131,12 +130,12 @@ int csync_add_exclude_list(CSYNC *ctx, const char *path);
|
|||
char *csync_get_config_dir(CSYNC *ctx);
|
||||
int csync_set_config_dir(CSYNC *ctx, const char *path);
|
||||
int csync_remove_config_dir(CSYNC *ctx);
|
||||
int csync_enable_journal(CSYNC *ctx);
|
||||
int csync_disable_journal(CSYNC *ctx);
|
||||
int csync_is_journal_disabled(CSYNC *ctx);
|
||||
int csync_enable_statedb(CSYNC *ctx);
|
||||
int csync_disable_statedb(CSYNC *ctx);
|
||||
int csync_is_statedb_disabled(CSYNC *ctx);
|
||||
csync_auth_callback csync_get_auth_callback(CSYNC *ctx);
|
||||
int csync_set_auth_callback(CSYNC *ctx, csync_auth_callback cb);
|
||||
char *csync_get_journal_file(CSYNC *ctx);
|
||||
char *csync_get_statedb_file(CSYNC *ctx);
|
||||
int csync_get_status(CSYNC *ctx);
|
||||
int csync_set_status(CSYNC *ctx, int status);
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ struct csync_s {
|
|||
sqlite3 *db;
|
||||
int exists;
|
||||
int disabled;
|
||||
} journal;
|
||||
} statedb;
|
||||
|
||||
struct {
|
||||
char *uri;
|
||||
|
|
|
@ -379,7 +379,7 @@ static int _csync_remove_file(CSYNC *ctx, csync_file_stat_t *st) {
|
|||
out:
|
||||
SAFE_FREE(uri);
|
||||
|
||||
/* Write to journal, to try again next run. */
|
||||
/* Write to statedb, to try again next run. */
|
||||
st->instruction = CSYNC_INSTRUCTION_NONE;
|
||||
|
||||
return rc;
|
||||
|
@ -649,7 +649,7 @@ static int _csync_propagation_cleanup(CSYNC *ctx) {
|
|||
}
|
||||
|
||||
if (csync_vio_rmdir(ctx, dir) < 0) {
|
||||
/* Write it back to journal, that we try to delete it next time. */
|
||||
/* Write it back to statedb, that we try to delete it next time. */
|
||||
st->instruction = CSYNC_INSTRUCTION_NONE;
|
||||
} else {
|
||||
st->instruction = CSYNC_INSTRUCTION_DELETED;
|
||||
|
|
|
@ -36,49 +36,49 @@
|
|||
#include "csync_statedb.h"
|
||||
#include "csync_util.h"
|
||||
|
||||
#define CSYNC_LOG_CATEGORY_NAME "csync.journal"
|
||||
#define CSYNC_LOG_CATEGORY_NAME "csync.statedb"
|
||||
#include "csync_log.h"
|
||||
|
||||
#define BUF_SIZE 16
|
||||
|
||||
void csync_set_journal_exists(CSYNC *ctx, int val) {
|
||||
ctx->journal.exists = val;
|
||||
void csync_set_statedb_exists(CSYNC *ctx, int val) {
|
||||
ctx->statedb.exists = val;
|
||||
}
|
||||
|
||||
int csync_get_journal_exists(CSYNC *ctx) {
|
||||
return ctx->journal.exists;
|
||||
int csync_get_statedb_exists(CSYNC *ctx) {
|
||||
return ctx->statedb.exists;
|
||||
}
|
||||
|
||||
static int _csync_journal_check(const char *journal) {
|
||||
static int _csync_statedb_check(const char *statedb) {
|
||||
int fd = -1;
|
||||
char buf[BUF_SIZE] = {0};
|
||||
sqlite3 *db = NULL;
|
||||
|
||||
/* check db version */
|
||||
fd = open(journal, O_RDONLY);
|
||||
fd = open(statedb, O_RDONLY);
|
||||
if (fd >= 0) {
|
||||
if (read(fd, (void *) buf, (size_t) BUF_SIZE - 1) >= 0) {
|
||||
buf[BUF_SIZE - 1] = '\0';
|
||||
close(fd);
|
||||
if (c_streq(buf, "SQLite format 3")) {
|
||||
if (sqlite3_open(journal, &db ) == SQLITE_OK) {
|
||||
if (sqlite3_open(statedb, &db ) == SQLITE_OK) {
|
||||
/* everything is fine */
|
||||
sqlite3_close(db);
|
||||
return 0;
|
||||
} else {
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_WARN, "database corrupted, removing!");
|
||||
unlink(journal);
|
||||
unlink(statedb);
|
||||
}
|
||||
sqlite3_close(db);
|
||||
} else {
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_WARN, "sqlite version mismatch");
|
||||
unlink(journal);
|
||||
unlink(statedb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* create database */
|
||||
if (sqlite3_open(journal, &db) == SQLITE_OK) {
|
||||
if (sqlite3_open(statedb, &db) == SQLITE_OK) {
|
||||
sqlite3_close(db);
|
||||
return 0;
|
||||
}
|
||||
|
@ -87,11 +87,11 @@ static int _csync_journal_check(const char *journal) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
static int _csync_journal_is_empty(CSYNC *ctx) {
|
||||
static int _csync_statedb_is_empty(CSYNC *ctx) {
|
||||
c_strlist_t *result = NULL;
|
||||
int rc = 0;
|
||||
|
||||
result = csync_journal_query(ctx, "SELECT COUNT(phash) FROM metadata LIMIT 1 OFFSET 0;");
|
||||
result = csync_statedb_query(ctx, "SELECT COUNT(phash) FROM metadata LIMIT 1 OFFSET 0;");
|
||||
if (result == NULL) {
|
||||
rc = 1;
|
||||
}
|
||||
|
@ -100,12 +100,12 @@ static int _csync_journal_is_empty(CSYNC *ctx) {
|
|||
return rc;
|
||||
}
|
||||
|
||||
int csync_journal_load(CSYNC *ctx, const char *journal) {
|
||||
int csync_statedb_load(CSYNC *ctx, const char *statedb) {
|
||||
int rc = -1;
|
||||
c_strlist_t *result = NULL;
|
||||
char *journal_tmp = NULL;
|
||||
char *statedb_tmp = NULL;
|
||||
|
||||
if (_csync_journal_check(journal) < 0) {
|
||||
if (_csync_statedb_check(statedb) < 0) {
|
||||
rc = -1;
|
||||
goto out;
|
||||
}
|
||||
|
@ -114,93 +114,93 @@ int csync_journal_load(CSYNC *ctx, const char *journal) {
|
|||
* We want a two phase commit for the jounal, so we create a temporary copy
|
||||
* of the database.
|
||||
* The intention is that if something goes wrong we will not loose the
|
||||
* journal.
|
||||
* statedb.
|
||||
*/
|
||||
if (asprintf(&journal_tmp, "%s.ctmp", journal) < 0) {
|
||||
if (asprintf(&statedb_tmp, "%s.ctmp", statedb) < 0) {
|
||||
rc = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (c_copy(journal, journal_tmp, 0644) < 0) {
|
||||
if (c_copy(statedb, statedb_tmp, 0644) < 0) {
|
||||
rc = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* Open the temporary database */
|
||||
if (sqlite3_open(journal_tmp, &ctx->journal.db) != SQLITE_OK) {
|
||||
if (sqlite3_open(statedb_tmp, &ctx->statedb.db) != SQLITE_OK) {
|
||||
rc = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (_csync_journal_is_empty(ctx)) {
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_NOTICE, "Journal doesn't exist");
|
||||
csync_set_journal_exists(ctx, 0);
|
||||
if (_csync_statedb_is_empty(ctx)) {
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_NOTICE, "statedb doesn't exist");
|
||||
csync_set_statedb_exists(ctx, 0);
|
||||
} else {
|
||||
csync_set_journal_exists(ctx, 1);
|
||||
csync_set_statedb_exists(ctx, 1);
|
||||
}
|
||||
|
||||
/* optimization for speeding up SQLite */
|
||||
result = csync_journal_query(ctx, "PRAGMA default_synchronous = OFF;");
|
||||
result = csync_statedb_query(ctx, "PRAGMA default_synchronous = OFF;");
|
||||
c_strlist_destroy(result);
|
||||
|
||||
rc = 0;
|
||||
out:
|
||||
SAFE_FREE(journal_tmp);
|
||||
SAFE_FREE(statedb_tmp);
|
||||
return rc;
|
||||
}
|
||||
|
||||
int csync_journal_write(CSYNC *ctx) {
|
||||
int csync_statedb_write(CSYNC *ctx) {
|
||||
/* drop tables */
|
||||
if (csync_journal_drop_tables(ctx) < 0) {
|
||||
if (csync_statedb_drop_tables(ctx) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* create tables */
|
||||
if (csync_journal_create_tables(ctx) < 0) {
|
||||
if (csync_statedb_create_tables(ctx) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* insert metadata */
|
||||
if (csync_journal_insert_metadata(ctx) < 0) {
|
||||
if (csync_statedb_insert_metadata(ctx) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int csync_journal_close(CSYNC *ctx, const char *journal, int jwritten) {
|
||||
char *journal_tmp = NULL;
|
||||
int csync_statedb_close(CSYNC *ctx, const char *statedb, int jwritten) {
|
||||
char *statedb_tmp = NULL;
|
||||
int rc = 0;
|
||||
|
||||
/* close the temporary database */
|
||||
sqlite3_close(ctx->journal.db);
|
||||
sqlite3_close(ctx->statedb.db);
|
||||
|
||||
if (asprintf(&journal_tmp, "%s.ctmp", journal) < 0) {
|
||||
if (asprintf(&statedb_tmp, "%s.ctmp", statedb) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* if we successfully synchronized, overwrite the original journal */
|
||||
/* if we successfully synchronized, overwrite the original statedb */
|
||||
if (jwritten) {
|
||||
rc = c_copy(journal_tmp, journal, 0644);
|
||||
rc = c_copy(statedb_tmp, statedb, 0644);
|
||||
if (rc == 0) {
|
||||
unlink(journal_tmp);
|
||||
unlink(statedb_tmp);
|
||||
}
|
||||
} else {
|
||||
unlink(journal_tmp);
|
||||
unlink(statedb_tmp);
|
||||
}
|
||||
SAFE_FREE(journal_tmp);
|
||||
SAFE_FREE(statedb_tmp);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int csync_journal_create_tables(CSYNC *ctx) {
|
||||
int csync_statedb_create_tables(CSYNC *ctx) {
|
||||
c_strlist_t *result = NULL;
|
||||
|
||||
/*
|
||||
* Create temorary table to work on, this speeds up the
|
||||
* creation of the journal.
|
||||
* creation of the statedb.
|
||||
*/
|
||||
result = csync_journal_query(ctx,
|
||||
result = csync_statedb_query(ctx,
|
||||
"CREATE TEMPORARY TABLE IF NOT EXISTS metadata_temp("
|
||||
"phash INTEGER(8),"
|
||||
"pathlen INTEGER,"
|
||||
|
@ -219,7 +219,7 @@ int csync_journal_create_tables(CSYNC *ctx) {
|
|||
}
|
||||
c_strlist_destroy(result);
|
||||
|
||||
result = csync_journal_query(ctx,
|
||||
result = csync_statedb_query(ctx,
|
||||
"CREATE TABLE IF NOT EXISTS metadata("
|
||||
"phash INTEGER(8),"
|
||||
"pathlen INTEGER,"
|
||||
|
@ -237,14 +237,14 @@ int csync_journal_create_tables(CSYNC *ctx) {
|
|||
}
|
||||
c_strlist_destroy(result);
|
||||
|
||||
result = csync_journal_query(ctx,
|
||||
result = csync_statedb_query(ctx,
|
||||
"CREATE INDEX metadata_phash ON metadata(phash);");
|
||||
if (result == NULL) {
|
||||
return -1;
|
||||
}
|
||||
c_strlist_destroy(result);
|
||||
|
||||
result = csync_journal_query(ctx,
|
||||
result = csync_statedb_query(ctx,
|
||||
"CREATE INDEX metadata_inode ON metadata(inode);");
|
||||
if (result == NULL) {
|
||||
return -1;
|
||||
|
@ -254,10 +254,10 @@ int csync_journal_create_tables(CSYNC *ctx) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int csync_journal_drop_tables(CSYNC *ctx) {
|
||||
int csync_statedb_drop_tables(CSYNC *ctx) {
|
||||
c_strlist_t *result = NULL;
|
||||
|
||||
result = csync_journal_query(ctx,
|
||||
result = csync_statedb_query(ctx,
|
||||
"DROP TABLE IF EXISTS metadata;"
|
||||
);
|
||||
if (result == NULL) {
|
||||
|
@ -279,7 +279,7 @@ static int _insert_metadata_visitor(void *obj, void *data) {
|
|||
|
||||
switch (fs->instruction) {
|
||||
/*
|
||||
* Don't write ignored, deleted or files with an error to the journal.
|
||||
* Don't write ignored, deleted or files with an error to the statedb.
|
||||
* They will be visited on the next synchronization again as a new file.
|
||||
*/
|
||||
case CSYNC_INSTRUCTION_DELETED:
|
||||
|
@ -322,13 +322,13 @@ static int _insert_metadata_visitor(void *obj, void *data) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
rc = csync_journal_insert(ctx, stmt);
|
||||
rc = csync_statedb_insert(ctx, stmt);
|
||||
|
||||
sqlite3_free(stmt);
|
||||
break;
|
||||
default:
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_WARN,
|
||||
"file: %s, instruction: %s (%d), not added to journal!",
|
||||
"file: %s, instruction: %s (%d), not added to statedb!",
|
||||
fs->path, csync_instruction_str(fs->instruction), fs->instruction);
|
||||
rc = 1;
|
||||
break;
|
||||
|
@ -337,18 +337,18 @@ static int _insert_metadata_visitor(void *obj, void *data) {
|
|||
return rc;
|
||||
}
|
||||
|
||||
int csync_journal_insert_metadata(CSYNC *ctx) {
|
||||
int csync_statedb_insert_metadata(CSYNC *ctx) {
|
||||
c_strlist_t *result = NULL;
|
||||
|
||||
if (c_rbtree_walk(ctx->local.tree, ctx, _insert_metadata_visitor) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (csync_journal_insert(ctx, "INSERT INTO metadata SELECT * FROM metadata_temp;") < 0) {
|
||||
if (csync_statedb_insert(ctx, "INSERT INTO metadata SELECT * FROM metadata_temp;") < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
result = csync_journal_query(ctx, "DROP TABLE metadata_temp;");
|
||||
result = csync_statedb_query(ctx, "DROP TABLE metadata_temp;");
|
||||
if (result == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -359,7 +359,7 @@ int csync_journal_insert_metadata(CSYNC *ctx) {
|
|||
}
|
||||
|
||||
/* caller must free the memory */
|
||||
csync_file_stat_t *csync_journal_get_stat_by_hash(CSYNC *ctx, uint64_t phash) {
|
||||
csync_file_stat_t *csync_statedb_get_stat_by_hash(CSYNC *ctx, uint64_t phash) {
|
||||
csync_file_stat_t *st = NULL;
|
||||
c_strlist_t *result = NULL;
|
||||
char *stmt = NULL;
|
||||
|
@ -371,7 +371,7 @@ csync_file_stat_t *csync_journal_get_stat_by_hash(CSYNC *ctx, uint64_t phash) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
result = csync_journal_query(ctx, stmt);
|
||||
result = csync_statedb_query(ctx, stmt);
|
||||
sqlite3_free(stmt);
|
||||
if (result == NULL) {
|
||||
return NULL;
|
||||
|
@ -403,7 +403,7 @@ csync_file_stat_t *csync_journal_get_stat_by_hash(CSYNC *ctx, uint64_t phash) {
|
|||
}
|
||||
|
||||
/* caller must free the memory */
|
||||
csync_file_stat_t *csync_journal_get_stat_by_inode(CSYNC *ctx, ino_t inode) {
|
||||
csync_file_stat_t *csync_statedb_get_stat_by_inode(CSYNC *ctx, ino_t inode) {
|
||||
csync_file_stat_t *st = NULL;
|
||||
c_strlist_t *result = NULL;
|
||||
char *stmt = NULL;
|
||||
|
@ -414,7 +414,7 @@ csync_file_stat_t *csync_journal_get_stat_by_inode(CSYNC *ctx, ino_t inode) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
result = csync_journal_query(ctx, stmt);
|
||||
result = csync_statedb_query(ctx, stmt);
|
||||
sqlite3_free(stmt);
|
||||
if (result == NULL) {
|
||||
return NULL;
|
||||
|
@ -447,8 +447,8 @@ csync_file_stat_t *csync_journal_get_stat_by_inode(CSYNC *ctx, ino_t inode) {
|
|||
return st;
|
||||
}
|
||||
|
||||
/* query the journal, caller must free the memory */
|
||||
c_strlist_t *csync_journal_query(CSYNC *ctx, const char *statement) {
|
||||
/* query the statedb, caller must free the memory */
|
||||
c_strlist_t *csync_statedb_query(CSYNC *ctx, const char *statement) {
|
||||
int err;
|
||||
int rc = 0;
|
||||
size_t i = 0;
|
||||
|
@ -467,14 +467,14 @@ c_strlist_t *csync_journal_query(CSYNC *ctx, const char *statement) {
|
|||
usleep(100000);
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "sqlite3_prepare: BUSY counter: %zu", busy_count);
|
||||
}
|
||||
err = sqlite3_prepare(ctx->journal.db, statement, -1, &stmt, &tail);
|
||||
err = sqlite3_prepare(ctx->statedb.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.db), statement);
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_WARN, "sqlite3_compile error: %s - on query %s", sqlite3_errmsg(ctx->statedb.db), statement);
|
||||
break;
|
||||
} else {
|
||||
busy_count = 0;
|
||||
|
@ -529,7 +529,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.db), statement);
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR, "sqlite_step error: %s - on query: %s", sqlite3_errmsg(ctx->statedb.db), statement);
|
||||
result = c_strlist_new(1);
|
||||
}
|
||||
|
||||
|
@ -549,7 +549,7 @@ c_strlist_t *csync_journal_query(CSYNC *ctx, const char *statement) {
|
|||
return result;
|
||||
}
|
||||
|
||||
int csync_journal_insert(CSYNC *ctx, const char *statement) {
|
||||
int csync_statedb_insert(CSYNC *ctx, const char *statement) {
|
||||
int err;
|
||||
int rc = 0;
|
||||
int busy_count = 0;
|
||||
|
@ -569,14 +569,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.db, statement, -1, &stmt, &tail);
|
||||
err = sqlite3_prepare(ctx->statedb.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.db), statement);
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR, "sqlite3_compile error: %s on query %s", sqlite3_errmsg(ctx->statedb.db), statement);
|
||||
break;
|
||||
} else {
|
||||
busy_count = 0;
|
||||
|
@ -608,7 +608,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.db), statement);
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR, "sqlite_step error: %s on insert: %s", sqlite3_errmsg(ctx->statedb.db), statement);
|
||||
}
|
||||
|
||||
if (rc == SQLITE_SCHEMA) {
|
||||
|
@ -623,6 +623,6 @@ int csync_journal_insert(CSYNC *ctx, const char *statement) {
|
|||
}
|
||||
} while (rc == SQLITE_SCHEMA && retry_count < 10);
|
||||
|
||||
return sqlite3_last_insert_rowid(ctx->journal.db);
|
||||
return sqlite3_last_insert_rowid(ctx->statedb.db);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,46 +25,46 @@
|
|||
*
|
||||
* @brief Private interface of csync
|
||||
*
|
||||
* @defgroup csyncJournalInternals csync journal internals
|
||||
* @defgroup csyncstatedbInternals csync statedb internals
|
||||
* @ingroup csyncInternalAPI
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _CSYNC_JOURNAL_H
|
||||
#define _CSYNC_JOURNAL_H
|
||||
#ifndef _CSYNC_STATEDB_H
|
||||
#define _CSYNC_STATEDB_H
|
||||
|
||||
#include "c_lib.h"
|
||||
#include "csync_private.h"
|
||||
|
||||
void csync_set_journal_exists(CSYNC *ctx, int val);
|
||||
void csync_set_statedb_exists(CSYNC *ctx, int val);
|
||||
|
||||
int csync_get_journal_exists(CSYNC *ctx);
|
||||
int csync_get_statedb_exists(CSYNC *ctx);
|
||||
|
||||
/**
|
||||
* @brief Load the journal.
|
||||
* @brief Load the statedb.
|
||||
*
|
||||
* This function tries to load the journal. If it doesn't exists it creates
|
||||
* This function tries to load the statedb. If it doesn't exists it creates
|
||||
* the sqlite3 database, but doesn't create the tables. This will be done when
|
||||
* csync gets destroyed.
|
||||
*
|
||||
* @param ctx The csync context.
|
||||
* @param journal Path to the journal file (sqlite3 db).
|
||||
* @param statedb Path to the statedb file (sqlite3 db).
|
||||
*
|
||||
* @return 0 on success, less than 0 if an error occured with errno set.
|
||||
*/
|
||||
int csync_journal_load(CSYNC *ctx, const char *journal);
|
||||
int csync_statedb_load(CSYNC *ctx, const char *statedb);
|
||||
|
||||
int csync_journal_write(CSYNC *ctx);
|
||||
int csync_statedb_write(CSYNC *ctx);
|
||||
|
||||
int csync_journal_close(CSYNC *ctx, const char *journal, int jwritten);
|
||||
int csync_statedb_close(CSYNC *ctx, const char *statedb, int jwritten);
|
||||
|
||||
csync_file_stat_t *csync_journal_get_stat_by_hash(CSYNC *ctx, uint64_t phash);
|
||||
csync_file_stat_t *csync_statedb_get_stat_by_hash(CSYNC *ctx, uint64_t phash);
|
||||
|
||||
csync_file_stat_t *csync_journal_get_stat_by_inode(CSYNC *ctx, ino_t inode);
|
||||
csync_file_stat_t *csync_statedb_get_stat_by_inode(CSYNC *ctx, ino_t inode);
|
||||
|
||||
/**
|
||||
* @brief A generic Journal query.
|
||||
* @brief A generic statedb query.
|
||||
*
|
||||
* @param ctx The csync context.
|
||||
* @param statement The SQL statement to execute
|
||||
|
@ -72,27 +72,27 @@ csync_file_stat_t *csync_journal_get_stat_by_inode(CSYNC *ctx, ino_t inode);
|
|||
* @return A stringlist of the entries of a column. An emtpy stringlist if
|
||||
* nothing has been found. NULL on error.
|
||||
*/
|
||||
c_strlist_t *csync_journal_query(CSYNC *ctx, const char *statement);
|
||||
c_strlist_t *csync_statedb_query(CSYNC *ctx, const char *statement);
|
||||
|
||||
/**
|
||||
* @brief Insert function for the journal.
|
||||
* @brief Insert function for the statedb.
|
||||
*
|
||||
* @param ctx The csync context.
|
||||
* @param statement The SQL statement to insert into the journal.
|
||||
* @param statement The SQL statement to insert into the statedb.
|
||||
*
|
||||
* @return The rowid of the most recent INSERT on success, 0 if the query
|
||||
* wasn't successful.
|
||||
*/
|
||||
int csync_journal_insert(CSYNC *ctx, const char *statement);
|
||||
int csync_statedb_insert(CSYNC *ctx, const char *statement);
|
||||
|
||||
int csync_journal_create_tables(CSYNC *ctx);
|
||||
int csync_statedb_create_tables(CSYNC *ctx);
|
||||
|
||||
int csync_journal_drop_tables(CSYNC *ctx);
|
||||
int csync_statedb_drop_tables(CSYNC *ctx);
|
||||
|
||||
int csync_journal_insert_metadata(CSYNC *ctx);
|
||||
int csync_statedb_insert_metadata(CSYNC *ctx);
|
||||
|
||||
/**
|
||||
* }@
|
||||
*/
|
||||
#endif /* _CSYNC_JOURNAL_H */
|
||||
#endif /* _CSYNC_STATEDB_H */
|
||||
|
||||
|
|
|
@ -89,14 +89,14 @@ static int _csync_detect_update(CSYNC *ctx, const char *file, const csync_vio_fi
|
|||
}
|
||||
|
||||
/* Update detection */
|
||||
if (csync_get_journal_exists(ctx)) {
|
||||
tmp = csync_journal_get_stat_by_hash(ctx, h);
|
||||
if (csync_get_statedb_exists(ctx)) {
|
||||
tmp = csync_statedb_get_stat_by_hash(ctx, h);
|
||||
if (tmp == NULL) {
|
||||
/* check if the file has been renamed */
|
||||
if (ctx->current == LOCAL_REPLICA) {
|
||||
tmp = csync_journal_get_stat_by_inode(ctx, fs->inode);
|
||||
tmp = csync_statedb_get_stat_by_inode(ctx, fs->inode);
|
||||
if (tmp == NULL) {
|
||||
/* file not found in journal */
|
||||
/* file not found in statedb */
|
||||
st->instruction = CSYNC_INSTRUCTION_NEW;
|
||||
goto out;
|
||||
} else {
|
||||
|
@ -105,7 +105,7 @@ static int _csync_detect_update(CSYNC *ctx, const char *file, const csync_vio_fi
|
|||
goto out;
|
||||
}
|
||||
}
|
||||
/* remote and file not found in journal */
|
||||
/* remote and file not found in statedb */
|
||||
st->instruction = CSYNC_INSTRUCTION_NEW;
|
||||
goto out;
|
||||
} else {
|
||||
|
|
|
@ -24,54 +24,54 @@ static void teardown(void) {
|
|||
fail_if(system("rm -rf /tmp/check_csync1") < 0, "Teardown failed");
|
||||
}
|
||||
|
||||
START_TEST (check_csync_journal_check)
|
||||
START_TEST (check_csync_statedb_check)
|
||||
{
|
||||
fail_if(system("mkdir -p /tmp/check_csync1") < 0, NULL);
|
||||
|
||||
/* old db */
|
||||
fail_if(system("echo \"SQLite format 2\" > /tmp/check_csync1/test.db") < 0, NULL);
|
||||
fail_unless(_csync_journal_check(testdb) == 0);
|
||||
fail_unless(_csync_statedb_check(testdb) == 0);
|
||||
|
||||
/* db already exists */
|
||||
fail_unless(_csync_journal_check(testdb) == 0);
|
||||
fail_unless(_csync_statedb_check(testdb) == 0);
|
||||
|
||||
/* no db exists */
|
||||
fail_if(system("rm -f /tmp/check_csync1/test.db") < 0, NULL);
|
||||
fail_unless(_csync_journal_check(testdb) == 0);
|
||||
fail_unless(_csync_statedb_check(testdb) == 0);
|
||||
|
||||
fail_unless(_csync_journal_check((char *) "/tmp/check_csync1/") < 0);
|
||||
fail_unless(_csync_statedb_check((char *) "/tmp/check_csync1/") < 0);
|
||||
|
||||
fail_if(system("rm -rf /tmp/check_csync1") < 0, NULL);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (check_csync_journal_load)
|
||||
START_TEST (check_csync_statedb_load)
|
||||
{
|
||||
struct stat sb;
|
||||
fail_unless(csync_journal_load(csync, testdb) == 0, NULL);
|
||||
fail_unless(csync_statedb_load(csync, testdb) == 0, NULL);
|
||||
|
||||
fail_unless(lstat(testtmpdb, &sb) == 0, NULL);
|
||||
|
||||
sqlite3_close(csync->journal.db);
|
||||
sqlite3_close(csync->statedb.db);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (check_csync_journal_close)
|
||||
START_TEST (check_csync_statedb_close)
|
||||
{
|
||||
struct stat sb;
|
||||
time_t modtime;
|
||||
/* journal not written */
|
||||
csync_journal_load(csync, testdb);
|
||||
/* statedb not written */
|
||||
csync_statedb_load(csync, testdb);
|
||||
|
||||
fail_unless(lstat(testdb, &sb) == 0, NULL);
|
||||
modtime = sb.st_mtime;
|
||||
|
||||
fail_unless(csync_journal_close(csync, testdb, 0) == 0, NULL);
|
||||
fail_unless(csync_statedb_close(csync, testdb, 0) == 0, NULL);
|
||||
|
||||
fail_unless(lstat(testdb, &sb) == 0, NULL);
|
||||
fail_unless(modtime == sb.st_mtime, NULL);
|
||||
|
||||
csync_journal_load(csync, testdb);
|
||||
csync_statedb_load(csync, testdb);
|
||||
|
||||
fail_unless(lstat(testdb, &sb) == 0, NULL);
|
||||
modtime = sb.st_mtime;
|
||||
|
@ -79,8 +79,8 @@ START_TEST (check_csync_journal_close)
|
|||
/* wait a sec or the modtime will be the same */
|
||||
sleep(1);
|
||||
|
||||
/* journal written */
|
||||
fail_unless(csync_journal_close(csync, testdb, 1) == 0, NULL);
|
||||
/* statedb written */
|
||||
fail_unless(csync_statedb_close(csync, testdb, 1) == 0, NULL);
|
||||
|
||||
fail_unless(lstat(testdb, &sb) == 0, NULL);
|
||||
fail_unless(modtime < sb.st_mtime, NULL);
|
||||
|
@ -88,11 +88,11 @@ START_TEST (check_csync_journal_close)
|
|||
END_TEST
|
||||
|
||||
static Suite *make_csync_suite(void) {
|
||||
Suite *s = suite_create("csync_journal");
|
||||
Suite *s = suite_create("csync_statedb");
|
||||
|
||||
create_case(s, "check_csync_journal_check", check_csync_journal_check);
|
||||
create_case_fixture(s, "check_csync_journal_load", check_csync_journal_load, setup, teardown);
|
||||
create_case_fixture(s, "check_csync_journal_close", check_csync_journal_close, setup, teardown);
|
||||
create_case(s, "check_csync_statedb_check", check_csync_statedb_check);
|
||||
create_case_fixture(s, "check_csync_statedb_load", check_csync_statedb_load, setup, teardown);
|
||||
create_case_fixture(s, "check_csync_statedb_close", check_csync_statedb_close, setup, teardown);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ static void setup_db(void) {
|
|||
fail_if(csync_create(&csync, "/tmp/check_csync1", "/tmp/check_csync2") < 0, "Setup failed");
|
||||
csync_set_config_dir(csync, "/tmp/check_csync/");
|
||||
fail_if(csync_init(csync) < 0, NULL, "Setup failed");
|
||||
fail_unless(csync_journal_create_tables(csync) == 0, "Setup failed");
|
||||
fail_unless(csync_statedb_create_tables(csync) == 0, "Setup failed");
|
||||
|
||||
stmt = sqlite3_mprintf("INSERT INTO metadata"
|
||||
"(phash, pathlen, path, inode, uid, gid, mode, modtime) VALUES"
|
||||
|
@ -47,7 +47,7 @@ static void setup_db(void) {
|
|||
42,
|
||||
42);
|
||||
|
||||
fail_if(csync_journal_insert(csync, stmt) < 0, NULL);
|
||||
fail_if(csync_statedb_insert(csync, stmt) < 0, NULL);
|
||||
sqlite3_free(stmt);
|
||||
}
|
||||
|
||||
|
@ -59,51 +59,51 @@ static void teardown(void) {
|
|||
}
|
||||
|
||||
|
||||
START_TEST (check_csync_journal_query_statement)
|
||||
START_TEST (check_csync_statedb_query_statement)
|
||||
{
|
||||
c_strlist_t *result = NULL;
|
||||
result = csync_journal_query(csync, "");
|
||||
result = csync_statedb_query(csync, "");
|
||||
fail_unless(result == NULL, NULL);
|
||||
c_strlist_destroy(result);
|
||||
|
||||
result = csync_journal_query(csync, "SELECT;");
|
||||
result = csync_statedb_query(csync, "SELECT;");
|
||||
fail_unless(result == NULL, NULL);
|
||||
c_strlist_destroy(result);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (check_csync_journal_create_error)
|
||||
START_TEST (check_csync_statedb_create_error)
|
||||
{
|
||||
c_strlist_t *result = NULL;
|
||||
result = csync_journal_query(csync, "CREATE TABLE test(phash INTEGER, text VARCHAR(10));");
|
||||
result = csync_statedb_query(csync, "CREATE TABLE test(phash INTEGER, text VARCHAR(10));");
|
||||
fail_if(result == NULL, NULL);
|
||||
c_strlist_destroy(result);
|
||||
|
||||
result = csync_journal_query(csync, "CREATE TABLE test(phash INTEGER, text VARCHAR(10));");
|
||||
result = csync_statedb_query(csync, "CREATE TABLE test(phash INTEGER, text VARCHAR(10));");
|
||||
fail_unless(result == NULL, NULL);
|
||||
c_strlist_destroy(result);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (check_csync_journal_insert_statement)
|
||||
START_TEST (check_csync_statedb_insert_statement)
|
||||
{
|
||||
c_strlist_t *result = NULL;
|
||||
result = csync_journal_query(csync, "CREATE TABLE test(phash INTEGER, text VARCHAR(10));");
|
||||
result = csync_statedb_query(csync, "CREATE TABLE test(phash INTEGER, text VARCHAR(10));");
|
||||
fail_if(result == NULL, NULL);
|
||||
c_strlist_destroy(result);
|
||||
fail_unless(csync_journal_insert(csync, "INSERT;") == 0, NULL);
|
||||
fail_unless(csync_journal_insert(csync, "INSERT") == 0, NULL);
|
||||
fail_unless(csync_journal_insert(csync, "") == 0, NULL);
|
||||
fail_unless(csync_statedb_insert(csync, "INSERT;") == 0, NULL);
|
||||
fail_unless(csync_statedb_insert(csync, "INSERT") == 0, NULL);
|
||||
fail_unless(csync_statedb_insert(csync, "") == 0, NULL);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (check_csync_journal_query_create_and_insert_table)
|
||||
START_TEST (check_csync_statedb_query_create_and_insert_table)
|
||||
{
|
||||
c_strlist_t *result = NULL;
|
||||
result = csync_journal_query(csync, "CREATE TABLE test(phash INTEGER, text VARCHAR(10));");
|
||||
result = csync_statedb_query(csync, "CREATE TABLE test(phash INTEGER, text VARCHAR(10));");
|
||||
c_strlist_destroy(result);
|
||||
fail_unless(csync_journal_insert(csync, "INSERT INTO test (phash, text) VALUES (42, 'hello');"), NULL);
|
||||
result = csync_journal_query(csync, "SELECT * FROM test;");
|
||||
fail_unless(csync_statedb_insert(csync, "INSERT INTO test (phash, text) VALUES (42, 'hello');"), NULL);
|
||||
result = csync_statedb_query(csync, "SELECT * FROM test;");
|
||||
fail_unless(result->count == 2, NULL);
|
||||
fail_unless(strcmp(result->vector[0], "42") == 0, NULL);
|
||||
fail_unless(strcmp(result->vector[1], "hello") == 0, NULL);
|
||||
|
@ -111,27 +111,27 @@ START_TEST (check_csync_journal_query_create_and_insert_table)
|
|||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (check_csync_journal_is_empty)
|
||||
START_TEST (check_csync_statedb_is_empty)
|
||||
{
|
||||
c_strlist_t *result = NULL;
|
||||
|
||||
/* we have an empty db */
|
||||
fail_unless(_csync_journal_is_empty(csync) == 1, NULL);
|
||||
fail_unless(_csync_statedb_is_empty(csync) == 1, NULL);
|
||||
|
||||
/* add a table and an entry */
|
||||
result = csync_journal_query(csync, "CREATE TABLE metadata(phash INTEGER, text VARCHAR(10));");
|
||||
result = csync_statedb_query(csync, "CREATE TABLE metadata(phash INTEGER, text VARCHAR(10));");
|
||||
c_strlist_destroy(result);
|
||||
fail_unless(csync_journal_insert(csync, "INSERT INTO metadata (phash, text) VALUES (42, 'hello');"), NULL);
|
||||
fail_unless(csync_statedb_insert(csync, "INSERT INTO metadata (phash, text) VALUES (42, 'hello');"), NULL);
|
||||
|
||||
fail_unless(_csync_journal_is_empty(csync) == 0, NULL);
|
||||
fail_unless(_csync_statedb_is_empty(csync) == 0, NULL);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (check_csync_journal_create_tables)
|
||||
START_TEST (check_csync_statedb_create_tables)
|
||||
{
|
||||
char *stmt = NULL;
|
||||
|
||||
fail_unless(csync_journal_create_tables(csync) == 0, NULL);
|
||||
fail_unless(csync_statedb_create_tables(csync) == 0, NULL);
|
||||
|
||||
stmt = sqlite3_mprintf("INSERT INTO metadata_temp"
|
||||
"(phash, pathlen, path, inode, uid, gid, mode, modtime) VALUES"
|
||||
|
@ -145,25 +145,25 @@ START_TEST (check_csync_journal_create_tables)
|
|||
42,
|
||||
42);
|
||||
|
||||
fail_if(csync_journal_insert(csync, stmt) < 0, NULL);
|
||||
fail_if(csync_statedb_insert(csync, stmt) < 0, NULL);
|
||||
sqlite3_free(stmt);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (check_csync_journal_drop_tables)
|
||||
START_TEST (check_csync_statedb_drop_tables)
|
||||
{
|
||||
fail_unless(csync_journal_drop_tables(csync) == 0, NULL);
|
||||
fail_unless(csync_journal_create_tables(csync) == 0, NULL);
|
||||
fail_unless(csync_journal_drop_tables(csync) == 0, NULL);
|
||||
fail_unless(csync_statedb_drop_tables(csync) == 0, NULL);
|
||||
fail_unless(csync_statedb_create_tables(csync) == 0, NULL);
|
||||
fail_unless(csync_statedb_drop_tables(csync) == 0, NULL);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (check_csync_journal_insert_metadata)
|
||||
START_TEST (check_csync_statedb_insert_metadata)
|
||||
{
|
||||
int i = 0;
|
||||
csync_file_stat_t *st;
|
||||
|
||||
fail_unless(csync_journal_create_tables(csync) == 0, NULL);
|
||||
fail_unless(csync_statedb_create_tables(csync) == 0, NULL);
|
||||
|
||||
for(i = 0; i < 100; i++) {
|
||||
st = c_malloc(sizeof(csync_file_stat_t));
|
||||
|
@ -172,11 +172,11 @@ START_TEST (check_csync_journal_insert_metadata)
|
|||
fail_unless(c_rbtree_insert(csync->local.tree, (void *) st) == 0, NULL);
|
||||
}
|
||||
|
||||
fail_unless(csync_journal_insert_metadata(csync) == 0, NULL);
|
||||
fail_unless(csync_statedb_insert_metadata(csync) == 0, NULL);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (check_csync_journal_write)
|
||||
START_TEST (check_csync_statedb_write)
|
||||
{
|
||||
int i = 0;
|
||||
csync_file_stat_t *st;
|
||||
|
@ -188,15 +188,15 @@ START_TEST (check_csync_journal_write)
|
|||
fail_unless(c_rbtree_insert(csync->local.tree, (void *) st) == 0, NULL);
|
||||
}
|
||||
|
||||
fail_unless(csync_journal_write(csync) == 0, NULL);
|
||||
fail_unless(csync_statedb_write(csync) == 0, NULL);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (check_csync_journal_get_stat_by_hash)
|
||||
START_TEST (check_csync_statedb_get_stat_by_hash)
|
||||
{
|
||||
csync_file_stat_t *tmp = NULL;
|
||||
|
||||
tmp = csync_journal_get_stat_by_hash(csync, (uint64_t) 42);
|
||||
tmp = csync_statedb_get_stat_by_hash(csync, (uint64_t) 42);
|
||||
fail_if(tmp == NULL, NULL);
|
||||
|
||||
fail_unless(tmp->phash == 42, NULL);
|
||||
|
@ -206,20 +206,20 @@ START_TEST (check_csync_journal_get_stat_by_hash)
|
|||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (check_csync_journal_get_stat_by_hash_not_found)
|
||||
START_TEST (check_csync_statedb_get_stat_by_hash_not_found)
|
||||
{
|
||||
csync_file_stat_t *tmp = NULL;
|
||||
|
||||
tmp = csync_journal_get_stat_by_hash(csync, (uint64_t) 666);
|
||||
tmp = csync_statedb_get_stat_by_hash(csync, (uint64_t) 666);
|
||||
fail_unless(tmp == NULL, NULL);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (check_csync_journal_get_stat_by_inode)
|
||||
START_TEST (check_csync_statedb_get_stat_by_inode)
|
||||
{
|
||||
csync_file_stat_t *tmp = NULL;
|
||||
|
||||
tmp = csync_journal_get_stat_by_inode(csync, (ino_t) 23);
|
||||
tmp = csync_statedb_get_stat_by_inode(csync, (ino_t) 23);
|
||||
fail_if(tmp == NULL, NULL);
|
||||
|
||||
fail_unless(tmp->phash == 42, NULL);
|
||||
|
@ -229,31 +229,31 @@ START_TEST (check_csync_journal_get_stat_by_inode)
|
|||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (check_csync_journal_get_stat_by_inode_not_found)
|
||||
START_TEST (check_csync_statedb_get_stat_by_inode_not_found)
|
||||
{
|
||||
csync_file_stat_t *tmp = NULL;
|
||||
|
||||
tmp = csync_journal_get_stat_by_inode(csync, (ino_t) 666);
|
||||
tmp = csync_statedb_get_stat_by_inode(csync, (ino_t) 666);
|
||||
fail_unless(tmp == NULL, NULL);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
static Suite *make_csync_suite(void) {
|
||||
Suite *s = suite_create("csync_journal");
|
||||
Suite *s = suite_create("csync_statedb");
|
||||
|
||||
create_case_fixture(s, "check_csync_journal_query_statement", check_csync_journal_query_statement, setup, teardown);
|
||||
create_case_fixture(s, "check_csync_journal_create_error", check_csync_journal_create_error, setup, teardown);
|
||||
create_case_fixture(s, "check_csync_journal_insert_statement", check_csync_journal_insert_statement, setup, teardown);
|
||||
create_case_fixture(s, "check_csync_journal_query_create_and_insert_table", check_csync_journal_query_create_and_insert_table, setup, teardown);
|
||||
create_case_fixture(s, "check_csync_journal_is_empty", check_csync_journal_is_empty, setup, teardown);
|
||||
create_case_fixture(s, "check_csync_journal_create_tables", check_csync_journal_create_tables, setup, teardown);
|
||||
create_case_fixture(s, "check_csync_journal_drop_tables", check_csync_journal_drop_tables, setup, teardown);
|
||||
create_case_fixture(s, "check_csync_journal_insert_metadata", check_csync_journal_insert_metadata, setup, teardown);
|
||||
create_case_fixture(s, "check_csync_journal_write", check_csync_journal_write, setup, teardown);
|
||||
create_case_fixture(s, "check_csync_journal_get_stat_by_hash", check_csync_journal_get_stat_by_hash, setup_db, teardown);
|
||||
create_case_fixture(s, "check_csync_journal_get_stat_by_hash_not_found", check_csync_journal_get_stat_by_hash_not_found, setup_db, teardown);
|
||||
create_case_fixture(s, "check_csync_journal_get_stat_by_inode", check_csync_journal_get_stat_by_inode, setup_db, teardown);
|
||||
create_case_fixture(s, "check_csync_journal_get_stat_by_inode_not_found", check_csync_journal_get_stat_by_inode_not_found, setup_db, teardown);
|
||||
create_case_fixture(s, "check_csync_statedb_query_statement", check_csync_statedb_query_statement, setup, teardown);
|
||||
create_case_fixture(s, "check_csync_statedb_create_error", check_csync_statedb_create_error, setup, teardown);
|
||||
create_case_fixture(s, "check_csync_statedb_insert_statement", check_csync_statedb_insert_statement, setup, teardown);
|
||||
create_case_fixture(s, "check_csync_statedb_query_create_and_insert_table", check_csync_statedb_query_create_and_insert_table, setup, teardown);
|
||||
create_case_fixture(s, "check_csync_statedb_is_empty", check_csync_statedb_is_empty, setup, teardown);
|
||||
create_case_fixture(s, "check_csync_statedb_create_tables", check_csync_statedb_create_tables, setup, teardown);
|
||||
create_case_fixture(s, "check_csync_statedb_drop_tables", check_csync_statedb_drop_tables, setup, teardown);
|
||||
create_case_fixture(s, "check_csync_statedb_insert_metadata", check_csync_statedb_insert_metadata, setup, teardown);
|
||||
create_case_fixture(s, "check_csync_statedb_write", check_csync_statedb_write, setup, teardown);
|
||||
create_case_fixture(s, "check_csync_statedb_get_stat_by_hash", check_csync_statedb_get_stat_by_hash, setup_db, teardown);
|
||||
create_case_fixture(s, "check_csync_statedb_get_stat_by_hash_not_found", check_csync_statedb_get_stat_by_hash_not_found, setup_db, teardown);
|
||||
create_case_fixture(s, "check_csync_statedb_get_stat_by_inode", check_csync_statedb_get_stat_by_inode, setup_db, teardown);
|
||||
create_case_fixture(s, "check_csync_statedb_get_stat_by_inode_not_found", check_csync_statedb_get_stat_by_inode_not_found, setup_db, teardown);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче