mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-27 17:37:36 +03:00
Revert "DB: Don't use metadata_tmp table"
Let's not do this in the release branch
This reverts commit 79f72a1211
.
This commit is contained in:
parent
6474780d80
commit
b923554935
2 changed files with 44 additions and 5 deletions
|
@ -394,6 +394,31 @@ int csync_statedb_create_tables(CSYNC *ctx) {
|
|||
int rc;
|
||||
char *stmt;
|
||||
|
||||
/*
|
||||
* Create temorary table to work on, this speeds up the
|
||||
* creation of the statedb.
|
||||
*/
|
||||
result = csync_statedb_query(ctx,
|
||||
"CREATE TABLE IF NOT EXISTS metadata_temp("
|
||||
"phash INTEGER(8),"
|
||||
"pathlen INTEGER,"
|
||||
"path VARCHAR(4096),"
|
||||
"inode INTEGER,"
|
||||
"uid INTEGER,"
|
||||
"gid INTEGER,"
|
||||
"mode INTEGER,"
|
||||
"modtime INTEGER(8),"
|
||||
"type INTEGER,"
|
||||
"md5 VARCHAR(32),"
|
||||
"PRIMARY KEY(phash)"
|
||||
");"
|
||||
);
|
||||
|
||||
if (result == NULL) {
|
||||
return -1;
|
||||
}
|
||||
c_strlist_destroy(result);
|
||||
|
||||
/*
|
||||
* Create 'real' table if not existing. That is only important at the
|
||||
* first sync so that other functions do not complain about missing
|
||||
|
@ -470,7 +495,7 @@ int csync_statedb_drop_tables(CSYNC *ctx) {
|
|||
c_strlist_t *result = NULL;
|
||||
|
||||
result = csync_statedb_query(ctx,
|
||||
"DROP TABLE IF EXISTS metadata;"
|
||||
"DROP TABLE IF EXISTS metadata_temp;"
|
||||
);
|
||||
if (result == NULL) {
|
||||
return -1;
|
||||
|
@ -540,7 +565,7 @@ static int _insert_metadata_visitor(void *obj, void *data) {
|
|||
|
||||
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_TRACE,
|
||||
"SQL statement: INSERT INTO metadata \n"
|
||||
"SQL statement: INSERT INTO metadata_temp \n"
|
||||
"\t\t\t(phash, pathlen, path, inode, uid, gid, mode, modtime, type, md5) VALUES \n"
|
||||
"\t\t\t(%lld, %lu, %s, %lld, %u, %u, %u, %lu, %d, %s);",
|
||||
(long long signed int) phash,
|
||||
|
@ -597,7 +622,7 @@ static int _insert_metadata_visitor(void *obj, void *data) {
|
|||
|
||||
int csync_statedb_insert_metadata(CSYNC *ctx) {
|
||||
c_strlist_t *result = NULL;
|
||||
char buffer[] = "INSERT INTO metadata VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10)";
|
||||
char buffer[] = "INSERT INTO metadata_temp VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10)";
|
||||
sqlite3_stmt* stmt;
|
||||
int rc;
|
||||
|
||||
|
@ -625,12 +650,22 @@ int csync_statedb_insert_metadata(CSYNC *ctx) {
|
|||
/* FIXME: How do we deal with an error in rbtree_walk? No rollback needed actually */
|
||||
if (rc < 0) {
|
||||
/* We stay with metadata and remove the tmp database */
|
||||
result = csync_statedb_query(ctx, "DELETE FROM metadata;");
|
||||
result = csync_statedb_query(ctx, "DROP TABLE metadata_temp;");
|
||||
c_strlist_destroy(result);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* If all goes well, drop metadata and rename metadata_temp */
|
||||
result = csync_statedb_query(ctx, "BEGIN TRANSACTION;");
|
||||
c_strlist_destroy(result);
|
||||
|
||||
result = csync_statedb_query(ctx, "DROP TABLE IF EXISTS metadata;");
|
||||
c_strlist_destroy(result);
|
||||
|
||||
result = csync_statedb_query(ctx, "ALTER TABLE metadata_temp RENAME TO metadata;");
|
||||
c_strlist_destroy(result);
|
||||
|
||||
result = csync_statedb_query(ctx,
|
||||
"CREATE INDEX IF NOT EXISTS metadata_phash ON metadata(phash);");
|
||||
if (result == NULL) {
|
||||
|
@ -645,6 +680,10 @@ int csync_statedb_insert_metadata(CSYNC *ctx) {
|
|||
}
|
||||
c_strlist_destroy(result);
|
||||
|
||||
|
||||
result = csync_statedb_query(ctx, "COMMIT TRANSACTION;");
|
||||
c_strlist_destroy(result);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -192,7 +192,7 @@ static void check_csync_statedb_create_tables(void **state)
|
|||
rc = csync_statedb_create_tables(csync);
|
||||
assert_int_equal(rc, 0);
|
||||
|
||||
stmt = sqlite3_mprintf("INSERT INTO metadata"
|
||||
stmt = sqlite3_mprintf("INSERT INTO metadata_temp"
|
||||
"(phash, pathlen, path, inode, uid, gid, mode, modtime, type, md5) VALUES"
|
||||
"(%lu, %d, '%q', %d, %d, %d, %d, %ld, %d, '%q');",
|
||||
(unsigned long)42,
|
||||
|
|
Loading…
Reference in a new issue