mirror of
https://github.com/nextcloud/desktop.git
synced 2024-10-24 21:35:47 +03:00
MD5 Support WIP
This commit is contained in:
parent
943e960bc0
commit
8e401e662f
6 changed files with 51 additions and 10 deletions
|
@ -89,6 +89,7 @@ typedef struct resource {
|
|||
enum resource_type type;
|
||||
dav_size_t size;
|
||||
time_t modtime;
|
||||
char md5[33];
|
||||
|
||||
struct resource *next;
|
||||
} resource;
|
||||
|
@ -142,6 +143,7 @@ static const ne_propname ls_props[] = {
|
|||
{ "DAV:", "getlastmodified" },
|
||||
{ "DAV:", "getcontentlength" },
|
||||
{ "DAV:", "resourcetype" },
|
||||
{ "DAV:", "getetag"},
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
|
@ -522,6 +524,7 @@ static void results(void *userdata,
|
|||
struct resource *newres = 0;
|
||||
const char *clength, *modtime = NULL;
|
||||
const char *resourcetype = NULL;
|
||||
const char *md5sum = NULL;
|
||||
const ne_status *status = NULL;
|
||||
char *path = ne_path_unescape( uri->path );
|
||||
|
||||
|
@ -561,6 +564,7 @@ static void results(void *userdata,
|
|||
modtime = ne_propset_value( set, &ls_props[0] );
|
||||
clength = ne_propset_value( set, &ls_props[1] );
|
||||
resourcetype = ne_propset_value( set, &ls_props[2] );
|
||||
md5sum = ne_propset_value( set, &ls_props[3] );
|
||||
|
||||
newres->type = resr_normal;
|
||||
if( clength == NULL && resourcetype && strncmp( resourcetype, "<DAV:collection>", 16 ) == 0) {
|
||||
|
@ -579,6 +583,12 @@ static void results(void *userdata,
|
|||
}
|
||||
}
|
||||
|
||||
if( md5sum ) {
|
||||
/* Skip the " around the string coming back from teh ne_propset_value call */
|
||||
strncpy( newres->md5, md5sum+1, 32 );
|
||||
DEBUG_WEBDAV("OOOOOOOOOOOOOOOOOOOOO %s", newres->md5);
|
||||
}
|
||||
|
||||
/* prepend the new resource to the result list */
|
||||
newres->next = fetchCtx->list;
|
||||
fetchCtx->list = newres;
|
||||
|
@ -690,7 +700,9 @@ static csync_vio_file_stat_t *resourceToFileStat( struct resource *res )
|
|||
lfs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_MTIME;
|
||||
lfs->size = res->size;
|
||||
lfs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_SIZE;
|
||||
|
||||
lfs->md5 = c_strdup(res->md5);
|
||||
DEBUG_WEBDAV("XXXXXXXXXXXXXXXXXXXXX MD5: %s", lfs->md5 );
|
||||
lfs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_MD5;
|
||||
return lfs;
|
||||
}
|
||||
|
||||
|
@ -791,10 +803,12 @@ static int owncloud_stat(const char *uri, csync_vio_file_stat_t *buf) {
|
|||
buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_SIZE;
|
||||
buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_MTIME;
|
||||
buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_PERMISSIONS;
|
||||
buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_MD5;
|
||||
|
||||
buf->fields = _fs.fields;
|
||||
buf->type = _fs.type;
|
||||
buf->mtime = _fs.mtime;
|
||||
buf->md5 = c_strdup( _fs.md5 );
|
||||
|
||||
buf->size = _fs.size;
|
||||
buf->mode = _stat_perms( _fs.type );
|
||||
|
@ -859,12 +873,14 @@ static int owncloud_stat(const char *uri, csync_vio_file_stat_t *buf) {
|
|||
buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_SIZE;
|
||||
buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_MTIME;
|
||||
buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_PERMISSIONS;
|
||||
buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_MD5;
|
||||
|
||||
buf->fields = lfs->fields;
|
||||
buf->type = lfs->type;
|
||||
buf->mtime = lfs->mtime;
|
||||
buf->size = lfs->size;
|
||||
buf->mode = _stat_perms( lfs->type );
|
||||
buf->md5 = c_strdup( lfs->md5 );
|
||||
|
||||
csync_vio_file_stat_destroy( lfs );
|
||||
}
|
||||
|
@ -1486,6 +1502,7 @@ static csync_vio_file_stat_t *owncloud_readdir(csync_vio_method_handle_t *dhandl
|
|||
_fs.fields = lfs->fields;
|
||||
_fs.type = lfs->type;
|
||||
_fs.size = lfs->size;
|
||||
_fs.md5 = c_strdup( lfs->md5 );
|
||||
}
|
||||
|
||||
/* DEBUG_WEBDAV("LFS fields: %s: %d", lfs->name, lfs->type ); */
|
||||
|
|
|
@ -213,6 +213,7 @@ int csync_statedb_create_tables(CSYNC *ctx) {
|
|||
"gid INTEGER,"
|
||||
"mode INTEGER,"
|
||||
"modtime INTEGER(8),"
|
||||
"md5 VARCHAR(32),"
|
||||
"PRIMARY KEY(phash)"
|
||||
");"
|
||||
);
|
||||
|
@ -232,6 +233,7 @@ int csync_statedb_create_tables(CSYNC *ctx) {
|
|||
"gid INTEGER,"
|
||||
"mode INTEGER,"
|
||||
"modtime INTEGER(8),"
|
||||
"md5 VARCHAR(32),"
|
||||
"PRIMARY KEY(phash)"
|
||||
");"
|
||||
);
|
||||
|
@ -254,6 +256,13 @@ int csync_statedb_create_tables(CSYNC *ctx) {
|
|||
}
|
||||
c_strlist_destroy(result);
|
||||
|
||||
result = csync_statedb_query(ctx,
|
||||
"CREATE INDEX metadata_md5 ON metadata(md5);");
|
||||
if (result == NULL) {
|
||||
return -1;
|
||||
}
|
||||
c_strlist_destroy(result);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -296,8 +305,8 @@ static int _insert_metadata_visitor(void *obj, void *data) {
|
|||
case CSYNC_INSTRUCTION_CONFLICT:
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_TRACE,
|
||||
"SQL statement: INSERT INTO metadata_temp \n"
|
||||
"\t\t\t(phash, pathlen, path, inode, uid, gid, mode, modtime) VALUES \n"
|
||||
"\t\t\t(%llu, %lu, %s, %llu, %u, %u, %u, %lu);",
|
||||
"\t\t\t(phash, pathlen, path, inode, uid, gid, mode, modtime, md5) VALUES \n"
|
||||
"\t\t\t(%llu, %lu, %s, %llu, %u, %u, %u, %lu, %s);",
|
||||
(long long unsigned int) fs->phash,
|
||||
(long unsigned int) fs->pathlen,
|
||||
fs->path,
|
||||
|
@ -305,14 +314,15 @@ static int _insert_metadata_visitor(void *obj, void *data) {
|
|||
fs->uid,
|
||||
fs->gid,
|
||||
fs->mode,
|
||||
fs->modtime);
|
||||
fs->modtime,
|
||||
fs->md5);
|
||||
|
||||
/*
|
||||
* The phash needs to be long long unsigned int or it segfaults on PPC
|
||||
*/
|
||||
stmt = sqlite3_mprintf("INSERT INTO metadata_temp "
|
||||
"(phash, pathlen, path, inode, uid, gid, mode, modtime) VALUES "
|
||||
"(%llu, %lu, '%q', %llu, %u, %u, %u, %lu);",
|
||||
"(phash, pathlen, path, inode, uid, gid, mode, modtime, md5) VALUES "
|
||||
"(%llu, %lu, '%q', %llu, %u, %u, %u, %lu, '%s');",
|
||||
(long long unsigned int) fs->phash,
|
||||
(long unsigned int) fs->pathlen,
|
||||
fs->path,
|
||||
|
@ -320,7 +330,8 @@ static int _insert_metadata_visitor(void *obj, void *data) {
|
|||
fs->uid,
|
||||
fs->gid,
|
||||
fs->mode,
|
||||
fs->modtime);
|
||||
fs->modtime,
|
||||
fs->md5);
|
||||
|
||||
if (stmt == NULL) {
|
||||
return -1;
|
||||
|
@ -413,7 +424,7 @@ csync_file_stat_t *csync_statedb_get_stat_by_hash(CSYNC *ctx, uint64_t phash) {
|
|||
st->gid = atoi(result->vector[5]);
|
||||
st->mode = atoi(result->vector[6]);
|
||||
st->modtime = strtoul(result->vector[7], NULL, 10);
|
||||
|
||||
st->md5 = c_strdup( result->vector[8] );
|
||||
c_strlist_destroy(result);
|
||||
|
||||
return st;
|
||||
|
@ -458,6 +469,7 @@ csync_file_stat_t *csync_statedb_get_stat_by_inode(CSYNC *ctx, uint64_t inode) {
|
|||
st->gid = atoi(result->vector[5]);
|
||||
st->mode = atoi(result->vector[6]);
|
||||
st->modtime = strtoul(result->vector[7], NULL, 10);
|
||||
st->md5 = c_strdup(result->vector[8]);
|
||||
|
||||
c_strlist_destroy(result);
|
||||
|
||||
|
|
|
@ -107,7 +107,8 @@ static int _csync_detect_update(CSYNC *ctx, const char *file,
|
|||
/* we have an update! */
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_TRACE, "time compare: %lu <-> %lu",
|
||||
fs->mtime, tmp->modtime);
|
||||
if (fs->mtime > tmp->modtime) {
|
||||
if( !c_streq(fs->md5, tmp->md5 )) {
|
||||
// if (!fs->mtime > tmp->modtime) {
|
||||
st->instruction = CSYNC_INSTRUCTION_EVAL;
|
||||
goto out;
|
||||
}
|
||||
|
@ -143,6 +144,7 @@ out:
|
|||
st->gid = fs->gid;
|
||||
st->nlink = fs->nlink;
|
||||
st->type = type;
|
||||
st->md5 = c_strdup(fs->md5);
|
||||
|
||||
st->phash = h;
|
||||
st->pathlen = len;
|
||||
|
|
|
@ -72,6 +72,7 @@ enum csync_vio_file_stat_fields_e {
|
|||
CSYNC_VIO_FILE_STAT_FIELDS_ACL = 1 << 14,
|
||||
CSYNC_VIO_FILE_STAT_FIELDS_UID = 1 << 15,
|
||||
CSYNC_VIO_FILE_STAT_FIELDS_GID = 1 << 16,
|
||||
CSYNC_VIO_FILE_STAT_FIELDS_MD5 = 1 << 17,
|
||||
};
|
||||
|
||||
|
||||
|
@ -83,6 +84,7 @@ struct csync_vio_file_stat_s {
|
|||
|
||||
void *acl;
|
||||
char *name;
|
||||
char *md5;
|
||||
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
|
|
|
@ -35,6 +35,8 @@
|
|||
#include "c_private.h"
|
||||
#include "c_lib.h"
|
||||
#include "c_string.h"
|
||||
#include "csync_util.h"
|
||||
#include "csync_log.h"
|
||||
|
||||
#include "vio/csync_vio_local.h"
|
||||
|
||||
|
@ -387,6 +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->fields |= CSYNC_VIO_FILE_STAT_FIELDS_MD5;
|
||||
|
||||
c_free_multibyte(wuri);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -134,6 +134,7 @@ static void fetch_a_context(void **state) {
|
|||
assert_true( fetchCtx->currResource->name != NULL );
|
||||
|
||||
printf( " %s -> %s\n", fetchCtx->currResource->uri, fetchCtx->currResource->name );
|
||||
printf( " MD5: %s\n", fetchCtx->currResource->md5);
|
||||
fetchCtx->currResource = fetchCtx->currResource->next;
|
||||
}
|
||||
}
|
||||
|
@ -299,11 +300,13 @@ int main(void) {
|
|||
const UnitTest tests[] = {
|
||||
unit_test(null_test_success),
|
||||
unit_test(connect_test_success),
|
||||
unit_test(fetch_a_context),
|
||||
unit_test_setup_teardown(test_setup_dirs, setup_toplevel_dir, teardown_toplevel_dir),
|
||||
unit_test(test_upload_files),
|
||||
unit_test(fetch_a_context),
|
||||
unit_test(test_download_files),
|
||||
};
|
||||
|
||||
srand(time(NULL));
|
||||
|
||||
return run_tests(tests);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue