mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-29 12:19:03 +03:00
Fill stat and add it to the red black tree.
Update detection needs still to be done.
This commit is contained in:
parent
fac0ba914f
commit
2ea310ab54
1 changed files with 72 additions and 9 deletions
|
@ -29,8 +29,11 @@
|
||||||
|
|
||||||
#include "c_lib.h"
|
#include "c_lib.h"
|
||||||
#include "c_jhash.h"
|
#include "c_jhash.h"
|
||||||
#include "csync_update.h"
|
|
||||||
|
#include "csync_private.h"
|
||||||
#include "csync_exclude.h"
|
#include "csync_exclude.h"
|
||||||
|
#include "csync_update.h"
|
||||||
|
|
||||||
#include "vio/csync_vio.h"
|
#include "vio/csync_vio.h"
|
||||||
|
|
||||||
#define CSYNC_LOG_CATEGORY_NAME "csync.updater"
|
#define CSYNC_LOG_CATEGORY_NAME "csync.updater"
|
||||||
|
@ -38,24 +41,84 @@
|
||||||
|
|
||||||
static int csync_detect_update(CSYNC *ctx, const char *file, const csync_vio_file_stat_t *fs, const int type) {
|
static int csync_detect_update(CSYNC *ctx, const char *file, const csync_vio_file_stat_t *fs, const int type) {
|
||||||
uint64_t h;
|
uint64_t h;
|
||||||
|
size_t len;
|
||||||
|
const char *path = NULL;
|
||||||
|
csync_file_stat_t *st = NULL;
|
||||||
|
|
||||||
if ((file == NULL) || (fs == NULL)) {
|
if ((file == NULL) || (fs == NULL)) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
h = c_jhash64((uint8_t *) file, strlen(file), 0);
|
switch (ctx->current) {
|
||||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_TRACE, "jhash for %s is: %lu", file, h);
|
case LOCAL_REPLICA:
|
||||||
|
path = file + strlen(ctx->local.uri) + 1;
|
||||||
|
break;
|
||||||
|
case REMOTE_REPLCIA:
|
||||||
|
path = file + strlen(ctx->remote.uri) + 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (path == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
len = strlen(path);
|
||||||
|
|
||||||
|
h = c_jhash64((uint8_t *) path, len, 0);
|
||||||
|
CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "Detect update for %s", path, h);
|
||||||
|
CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, " hash:\t\t%lu", h);
|
||||||
|
|
||||||
|
st = c_malloc(sizeof(csync_file_stat_t) + len + 1);
|
||||||
|
if (st == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, " stat size:\t%d", sizeof(csync_file_stat_t) + len + 1);
|
||||||
|
|
||||||
|
/* Check if file is excluded */
|
||||||
|
if (csync_excluded(ctx, path)) {
|
||||||
|
st->instruction = CSYNC_INSTRUCTION_IGNORE;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* TODO: Update detection */
|
||||||
|
/* if current replica, search for inode and compare hash */
|
||||||
|
st->instruction = CSYNC_INSTRUCTION_NONE;
|
||||||
|
|
||||||
|
out:
|
||||||
|
st->inode = fs->inode;
|
||||||
|
st->mode = fs->mode;
|
||||||
|
st->modtime = fs->mtime;
|
||||||
|
st->uid = fs->uid;
|
||||||
|
st->gid = fs->gid;
|
||||||
|
st->nlink = fs->link_count;
|
||||||
|
st->type = type;
|
||||||
|
|
||||||
|
st->phash = h;
|
||||||
|
st->pathlen = len;
|
||||||
|
memcpy(st->path, (len ? path : ""), len + 1);
|
||||||
|
|
||||||
|
switch (ctx->current) {
|
||||||
|
case LOCAL_REPLICA:
|
||||||
|
if (c_rbtree_insert(ctx->local.tree, (void *) st) < 0) {
|
||||||
|
SAFE_FREE(st);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case REMOTE_REPLCIA:
|
||||||
|
if (c_rbtree_insert(ctx->remote.tree, (void *) st) < 0) {
|
||||||
|
SAFE_FREE(st);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int csync_walker(CSYNC *ctx, const char *file, const csync_vio_file_stat_t *fs, enum csync_ftw_flags_e flag) {
|
int csync_walker(CSYNC *ctx, const char *file, const csync_vio_file_stat_t *fs, enum csync_ftw_flags_e flag) {
|
||||||
/* Check if file is excluded */
|
|
||||||
if (csync_excluded(ctx, file)) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (flag) {
|
switch (flag) {
|
||||||
case CSYNC_FTW_FLAG_FILE:
|
case CSYNC_FTW_FLAG_FILE:
|
||||||
case CSYNC_FTW_FLAG_SLINK:
|
case CSYNC_FTW_FLAG_SLINK:
|
||||||
|
@ -140,7 +203,7 @@ int csync_ftw(CSYNC *ctx, const char *uri, csync_walker_fn fn, unsigned int dept
|
||||||
flag = CSYNC_FTW_FLAG_NSTAT;
|
flag = CSYNC_FTW_FLAG_NSTAT;
|
||||||
}
|
}
|
||||||
|
|
||||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "Walking %s", filename);
|
CSYNC_LOG(CSYNC_LOG_PRIORITY_TRACE, "Walking %s", filename);
|
||||||
|
|
||||||
/* Call walker function for each file */
|
/* Call walker function for each file */
|
||||||
rc = fn(ctx, filename, fs, flag);
|
rc = fn(ctx, filename, fs, flag);
|
||||||
|
|
Loading…
Reference in a new issue