mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-23 13:35:58 +03:00
UniqID based syncing, first WIP state.
This commit is contained in:
parent
d2ba37a419
commit
ae5394ad75
6 changed files with 56 additions and 2 deletions
|
@ -332,6 +332,12 @@ static int _csync_push_file(CSYNC *ctx, csync_file_stat_t *st) {
|
|||
rc = 1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if( st->md5 ) {
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "UUUU MD5 sum: %s", st->md5);
|
||||
} else {
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "MD5 sum is empty");
|
||||
}
|
||||
}
|
||||
|
||||
if (_push_to_tmp_first(ctx)) {
|
||||
|
|
|
@ -476,6 +476,28 @@ csync_file_stat_t *csync_statedb_get_stat_by_inode(CSYNC *ctx, uint64_t inode) {
|
|||
return st;
|
||||
}
|
||||
|
||||
char *csync_statedb_get_uniqId( CSYNC *ctx, uint64_t jHash, csync_vio_file_stat_t *buf ) {
|
||||
char *ret = NULL;
|
||||
c_strlist_t *result = NULL;
|
||||
char *stmt = NULL;
|
||||
|
||||
stmt = sqlite3_mprintf("SELECT md5 FROM metadata WHERE phash='%llu' AND modtime=%llu", jHash, buf->mtime);
|
||||
result = csync_statedb_query(ctx, stmt);
|
||||
sqlite3_free(stmt);
|
||||
if (result == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (result->count == 1) {
|
||||
/* phash, pathlen, path, inode, uid, gid, mode, modtime */
|
||||
ret = c_strdup( result->vector[0] );
|
||||
}
|
||||
|
||||
c_strlist_destroy(result);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* query the statedb, caller must free the memory */
|
||||
c_strlist_t *csync_statedb_query(CSYNC *ctx, const char *statement) {
|
||||
int err = SQLITE_OK;
|
||||
|
|
|
@ -61,6 +61,7 @@ csync_file_stat_t *csync_statedb_get_stat_by_hash(CSYNC *ctx, uint64_t phash);
|
|||
|
||||
csync_file_stat_t *csync_statedb_get_stat_by_inode(CSYNC *ctx, uint64_t inode);
|
||||
|
||||
char *csync_statedb_get_uniqId( CSYNC *ctx, uint64_t jHash, csync_vio_file_stat_t *buf );
|
||||
/**
|
||||
* @brief A generic statedb query.
|
||||
*
|
||||
|
|
|
@ -103,10 +103,26 @@ static int _csync_detect_update(CSYNC *ctx, const char *file,
|
|||
*/
|
||||
if (csync_get_statedb_exists(ctx)) {
|
||||
tmp = csync_statedb_get_stat_by_hash(ctx, h);
|
||||
#if 0
|
||||
/* this code could possibly replace the one in csync_vio.c stat and would be more efficient */
|
||||
if(tmp) {
|
||||
if( ctx->current == LOCAL_REPLICA ) {
|
||||
if(fs->mtime == tmp->modtime && fs->size == tmp->size) {
|
||||
/* filesystem modtime is still the same as the db mtime
|
||||
* thus the md5 sum is still valid. */
|
||||
fs->md5 = c_strdup( tmp->md5 );
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (tmp && tmp->phash == h) {
|
||||
/* we have an update! */
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_TRACE, "time compare: %lu <-> %lu",
|
||||
fs->mtime, tmp->modtime);
|
||||
if( !fs->md5) {
|
||||
st->instruction = CSYNC_INSTRUCTION_EVAL;
|
||||
goto out;
|
||||
}
|
||||
if( !c_streq(fs->md5, tmp->md5 )) {
|
||||
// if (!fs->mtime > tmp->modtime) {
|
||||
st->instruction = CSYNC_INSTRUCTION_EVAL;
|
||||
|
@ -144,7 +160,9 @@ out:
|
|||
st->gid = fs->gid;
|
||||
st->nlink = fs->nlink;
|
||||
st->type = type;
|
||||
st->md5 = c_strdup(fs->md5);
|
||||
st->md5 = NULL;
|
||||
if( fs->md5 )
|
||||
st->md5 = c_strdup(fs->md5);
|
||||
|
||||
st->phash = h;
|
||||
st->pathlen = len;
|
||||
|
|
|
@ -118,6 +118,7 @@ static int _merge_file_trees_visitor(void *obj, void *data) {
|
|||
CSYNC *ctx = NULL;
|
||||
c_rbtree_t *tree = NULL;
|
||||
c_rbnode_t *node = NULL;
|
||||
char *md5 = NULL;
|
||||
|
||||
char errbuf[256] = {0};
|
||||
char *uri = NULL;
|
||||
|
@ -178,7 +179,9 @@ static int _merge_file_trees_visitor(void *obj, void *data) {
|
|||
goto out;
|
||||
}
|
||||
}
|
||||
md5 = fs->md5;
|
||||
fs = c_rbtree_node_data(node);
|
||||
fs->md5 = md5;
|
||||
|
||||
switch (ctx->current) {
|
||||
case LOCAL_REPLICA:
|
||||
|
@ -218,6 +221,8 @@ static int _merge_file_trees_visitor(void *obj, void *data) {
|
|||
/* update file stat */
|
||||
fs->inode = vst->inode;
|
||||
fs->modtime = vst->mtime;
|
||||
// if( vst->md5 )
|
||||
// fs->md5 = c_strdup(vst->md5);
|
||||
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "file: %s, instruction: UPDATED", uri);
|
||||
|
||||
|
|
|
@ -389,7 +389,9 @@ int csync_vio_local_stat(const char *uri, csync_vio_file_stat_t *buf) {
|
|||
buf->ctime = sb.st_ctime;
|
||||
buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_CTIME;
|
||||
|
||||
buf->md5 = csync_file_md5( uri );
|
||||
/* buf->md5 = csync_file_md5( uri ); */
|
||||
/* md5 is queried one level higher because we do not have ctx here. */
|
||||
|
||||
buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_MD5;
|
||||
|
||||
c_free_multibyte(wuri);
|
||||
|
|
Loading…
Reference in a new issue