mirror of
https://github.com/nextcloud/desktop.git
synced 2024-10-25 13:55:47 +03:00
Improve the update detection.
Document and fix a problem in getting the phash value.
This commit is contained in:
parent
971e3301e3
commit
f400f1852f
2 changed files with 32 additions and 22 deletions
|
@ -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]);
|
||||
|
|
|
@ -98,36 +98,33 @@ 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;
|
||||
}
|
||||
} else {
|
||||
st->instruction = CSYNC_INSTRUCTION_NEW;
|
||||
}
|
||||
|
||||
out:
|
||||
SAFE_FREE(tmp);
|
||||
|
|
Loading…
Reference in a new issue