# HG changeset patch # User Olaf Wintermann # Date 1552678209 -3600 # Node ID d53fd1006485f9e6eebc98d02cd0560530547145 # Parent 923a4528a2ae51f6cfc896fa0c639cd2386e5e2a store hash of remote xattr and tags in sync db diff -r 923a4528a2ae -r d53fd1006485 dav/db.c --- a/dav/db.c Thu Mar 14 17:43:31 2019 +0100 +++ b/dav/db.c Fri Mar 15 20:30:09 2019 +0100 @@ -133,6 +133,10 @@ field = 7; } else if(xstreq(name, "xattr-hash")) { field = 8; + } else if(xstreq(name, "remote-tags-hash")) { + field = 9; + } else if(xstreq(name, "remote-xattr-hash")) { + field = 10; } else if(xstreq(name, "skipped")) { res->skipped = TRUE; } else if(xstreq(name, "tags-updated")) { @@ -205,6 +209,14 @@ res->xattr_hash = strdup((char*)value); break; } + case 9: { + res->remote_tags_hash = strdup((char*)value); + break; + } + case 10: { + res->remote_xattr_hash = strdup((char*)value); + break; + } } } else if(XML_READER_TYPE_END_ELEMENT) { if(xstreq(name, "resource")) { @@ -370,7 +382,7 @@ BAD_CAST "tags-hash", BAD_CAST res->tags_hash); if(r < 0) { - fprintf(stderr, "Cannot write tags-hash: %s\n", res->etag); + fprintf(stderr, "Cannot write tags-hash: %s\n", res->tags_hash); xmlFreeTextWriter(writer); return -1; } @@ -382,7 +394,31 @@ BAD_CAST "xattr-hash", BAD_CAST res->xattr_hash); if(r < 0) { - fprintf(stderr, "Cannot write xattr-hash: %s\n", res->etag); + fprintf(stderr, "Cannot write xattr-hash: %s\n", res->xattr_hash); + xmlFreeTextWriter(writer); + return -1; + } + } + + if(res->remote_tags_hash) { + r = xmlTextWriterWriteElement( + writer, + BAD_CAST "remote-tags-hash", + BAD_CAST res->remote_tags_hash); + if(r < 0) { + fprintf(stderr, "Cannot write remote-tags-hash: %s\n", res->remote_tags_hash); + xmlFreeTextWriter(writer); + return -1; + } + } + + if(res->remote_xattr_hash) { + r = xmlTextWriterWriteElement( + writer, + BAD_CAST "remote-xattr-hash", + BAD_CAST res->remote_xattr_hash); + if(r < 0) { + fprintf(stderr, "Cannot write remote-tags-hash: %s\n", res->remote_xattr_hash); xmlFreeTextWriter(writer); return -1; } diff -r 923a4528a2ae -r d53fd1006485 dav/db.h --- a/dav/db.h Thu Mar 14 17:43:31 2019 +0100 +++ b/dav/db.h Fri Mar 15 20:30:09 2019 +0100 @@ -64,6 +64,8 @@ XAttributes *xattr; char *tags_hash; char *xattr_hash; + char *remote_tags_hash; + char *remote_xattr_hash; DavBool tags_updated; DavBool finfo_updated; diff -r 923a4528a2ae -r d53fd1006485 dav/finfo.c --- a/dav/finfo.c Thu Mar 14 17:43:31 2019 +0100 +++ b/dav/finfo.c Fri Mar 15 20:30:09 2019 +0100 @@ -169,7 +169,12 @@ free(attributes); - return xattr; + if(nattr > 0) { + return xattr; + } else { + xattributes_free(xattr); + return NULL; + } } int resource_set_xattr(DavResource *res, XAttributes *xattr) { @@ -200,5 +205,10 @@ } void xattributes_free(XAttributes *xattr) { - + free(xattr->hash); + for(int i=0;inattr;i++) { + free(xattr->names[i]); + free(xattr->values[i].ptr); + } + free(xattr); } diff -r 923a4528a2ae -r d53fd1006485 dav/sync.c --- a/dav/sync.c Thu Mar 14 17:43:31 2019 +0100 +++ b/dav/sync.c Fri Mar 15 20:30:09 2019 +0100 @@ -822,6 +822,14 @@ ret = REMOTE_CHANGE_NEW; } + if(ret == REMOTE_NO_CHANGE) { + // check if tags have changed + if(dir->tagconfig) { + + } + + } + free(local_path); return ret; } @@ -1791,9 +1799,10 @@ if(dir->metadata & FINFO_XATTR == FINFO_XATTR) { char *path = util_concat_path(dir->path, db_res->path); XAttributes *xattr = file_get_attributes(path); + // test if xattr are added, removed or changed if((db_res->xattr_hash && !xattr) || (!db_res->xattr_hash && xattr) || - strcmp(xattr->hash, db_res->xattr_hash)) + (xattr && db_res->xattr_hash && strcmp(xattr->hash, db_res->xattr_hash))) { res->metadata_updated = 1; res->xattr_updated = 1; diff -r 923a4528a2ae -r d53fd1006485 dav/tags.c --- a/dav/tags.c Thu Mar 14 17:43:31 2019 +0100 +++ b/dav/tags.c Fri Mar 15 20:30:09 2019 +0100 @@ -34,6 +34,8 @@ #include #include +#include + #include "libxattr.h" #include "tags.h" @@ -50,6 +52,11 @@ free(tag); } +void free_taglist(UcxList *list) { + ucx_list_free_content(list, (ucx_destructor)free_dav_tag); + ucx_list_free(list); +} + int compare_tagname(DavTag* left, DavTag* right, void* ignorecase) { sstr_t leftname = sstr(left->name); sstr_t rightname = sstr(right->name); @@ -359,6 +366,38 @@ #endif +int compare_taglists(UcxList *tags1, UcxList *tags2) { + if(!tags1) { + return tags2 ? 0 : 1; + } + if(!tags2) { + return tags1 ? 0 : 1; + } + + UcxMap *map1 = ucx_map_new(32); + UCX_FOREACH(elm, tags1) { + DavTag *t = elm->data; + ucx_map_cstr_put(map1, t->name, t); + } + + int equal = 1; + int i = 0; + UCX_FOREACH(elm, tags2) { + DavTag *t = elm->data; + if(!ucx_map_cstr_get(map1, t->name)) { + equal = 0; + break; + } + i++; + } + + if(i != map1->count) { + equal = 0; + } + ucx_map_free(map1); + return equal; +} + /* ----------- ----------- tag filter ---------------------- */ static size_t rtrimskip(scstr_t str, size_t skip) { diff -r 923a4528a2ae -r d53fd1006485 dav/tags.h --- a/dav/tags.h Thu Mar 14 17:43:31 2019 +0100 +++ b/dav/tags.h Fri Mar 15 20:30:09 2019 +0100 @@ -72,6 +72,8 @@ void free_dav_tag(DavTag* tag); +void free_taglist(UcxList *list); + int compare_tagname(DavTag* left, DavTag* right, void* ignorecase); UcxList* parse_text_taglist(const char *buf, size_t length); @@ -86,6 +88,7 @@ UcxList* parse_macos_taglist(const char *buf, size_t length); UcxBuffer* create_macos_taglist(UcxList *tags); +int compare_taglists(UcxList *tags1, UcxList *tags2); /* ----------- ----------- tag filter ---------------------- */