diff --git a/src/csync_statedb.c b/src/csync_statedb.c index d64a88b8e..1edb02aa4 100644 --- a/src/csync_statedb.c +++ b/src/csync_statedb.c @@ -388,7 +388,20 @@ csync_file_stat_t *csync_statedb_get_stat_by_hash(CSYNC *ctx, uint64_t phash) { c_strlist_destroy(result); return NULL; } - st->phash = strtoull(result->vector[0], NULL, 10); + + /* + * FIXME: + * We use an INTEGER(8) which is signed to the phash in the sqlite3 db, + * but the phash is an uint64_t. So for some values we get a string like + * "1.66514565505016e+19". For such a string strtoull() returns 1. + * phash = 1 + * + * st->phash = strtoull(result->vector[0], NULL, 10); + */ + + /* The query suceeded so use the phash we pass to the function. */ + st->phash = phash; + st->pathlen = atoi(result->vector[1]); memcpy(st->path, (len ? result->vector[2] : ""), len + 1); st->inode = atoi(result->vector[3]); diff --git a/src/csync_update.c b/src/csync_update.c index df6a12864..f00ae64ac 100644 --- a/src/csync_update.c +++ b/src/csync_update.c @@ -98,35 +98,32 @@ static int _csync_detect_update(CSYNC *ctx, const char *file, const csync_vio_fi /* Update detection */ 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_statedb_get_stat_by_inode(ctx, fs->inode); - if (tmp == NULL) { - /* file not found in statedb */ - st->instruction = CSYNC_INSTRUCTION_NEW; - goto out; - } else { - /* inode found so the file has been renamed */ - st->instruction = CSYNC_INSTRUCTION_RENAME; - goto out; - } - } - /* remote and file not found in statedb */ - st->instruction = CSYNC_INSTRUCTION_NEW; - goto out; - } else { + if (tmp && tmp->phash == h) { /* we have an update! */ if (fs->mtime > tmp->modtime) { st->instruction = CSYNC_INSTRUCTION_EVAL; goto out; } - /* FIXME: check mode too? */ + st->instruction = CSYNC_INSTRUCTION_NONE; + } else { + /* check if the file has been renamed */ + if (ctx->current == LOCAL_REPLICA) { + tmp = csync_statedb_get_stat_by_inode(ctx, fs->inode); + if (tmp && tmp->inode == fs->inode) { + /* inode found so the file has been renamed */ + st->instruction = CSYNC_INSTRUCTION_RENAME; + goto out; + } else { + /* file not found in statedb */ + st->instruction = CSYNC_INSTRUCTION_NEW; + goto out; + } + } + /* remote and file not found in statedb */ + st->instruction = CSYNC_INSTRUCTION_NEW; } - st->instruction = CSYNC_INSTRUCTION_NONE; } else { st->instruction = CSYNC_INSTRUCTION_NEW; - goto out; } out: