Sun, 04 Feb 2018 12:36:26 +0100
pushing tags should work now
dav/sync.c | file | annotate | diff | comparison | revisions |
--- a/dav/sync.c Sun Feb 04 11:14:20 2018 +0100 +++ b/dav/sync.c Sun Feb 04 12:36:26 2018 +0100 @@ -973,22 +973,7 @@ } if(dir->tagconfig && local_res->tags_updated && !abort) { - // get tags from tagstore (xattr or something else) - // and store it in resource property - UcxList *tags = sync_get_file_tags(dir, local_res, NULL); - DavXmlNode *prop = create_xml_taglist(tags); - if(prop) { - dav_set_property_ns(res, DAV_NS, "tags", prop); - printf("update: %s\n", local_res->path); - if(dav_store(res)) { - print_resource_error(sn, local_res->path); - ret = -1; - sync_error++; - } else { - sync_success++; - local_res->tags_updated = 0; - } - } + sync_update_tags(dir, sn, res, local_res); } } else { // dav_exists() failed @@ -1248,6 +1233,9 @@ if(db_res->etag) { res->etag = strdup(db_res->etag); } + if(db_res->tags_hash) { + res->tags_hash = strdup(db_res->tags_hash); + } if(dir->tagconfig && dir->tagconfig->detect_changes && !res->tags_updated) { UcxBuffer *tags = sync_get_file_tag_data(dir, res); @@ -1261,6 +1249,8 @@ } else { res->tags_updated = 1; } + } else if(db_res->tags_hash) { + res->tags_updated = 1; // tags removed } } @@ -1538,7 +1528,7 @@ dav_set_content(res, in, (dav_read_func)fread); if(dir->tagconfig) { - UcxList *tags = sync_get_file_tags(dir, local, NULL); // TODO: check remote tags + UcxList *tags = sync_get_file_tags(dir, local, NULL); DavXmlNode *prop = create_xml_taglist(tags); if(prop) { dav_set_property_ns(res, DAV_NS, "tags", prop); @@ -1671,73 +1661,34 @@ } int sync_update_tags(SyncDirectory *dir, DavSession *sn, DavResource *res, LocalResource *local) { - if(!dir->tagconfig) { + if(!dir->tagconfig || !local->tags_updated) { return 0; } // get local tags - DavBool changed = FALSE; - UcxList *tags = sync_get_file_tags(dir, local, &changed); - if(!tags || !changed) { - return 0; + UcxList *tags = sync_get_file_tags(dir, local, NULL); + + DavXmlNode *prop = create_xml_taglist(tags); + if(prop) { + dav_set_property_ns(res, DAV_NS, "tags", prop); + } else { + dav_remove_property_ns(res, DAV_NS, "tags"); } - // local tags changed - DavBool update_tags = TRUE; - if(dir->tagconfig->conflict != TAG_NO_CONFLICT) { - // get tags from the server - DavXmlNode *tagsprop = dav_get_property_ns(res, DAV_NS, "tags"); - UcxList *remote_tags = NULL; - if(tagsprop) { - remote_tags = parse_dav_xml_taglist(tagsprop); + printf("update: %s\n", local->path); + if(dav_store(res)) { + print_resource_error(sn, local->path); + } else { + UcxBuffer *tag_data = local->cached_tags; + if(local->tags_hash) { + free(local->tags_hash); + local->tags_hash = NULL; } - - if(remote_tags) { - // compare the local tags with server tags - DavBool tags_equal = TRUE; - UcxList *local_t = tags; - UcxList *remote_t = remote_tags; - while(local_t) { - if(!remote_t) { - tags_equal = FALSE; - break; - } - - DavTag *lt = local_t->data; - DavTag *rt = remote_t->data; - if(strcmp(lt->name, rt->name)) { - tags_equal = FALSE; - break; - } - - local_t = local_t->next; - remote_t = remote_t->next; - } - - if(!tags_equal) { - switch(dir->tagconfig->conflict) { - case TAG_KEEP_LOCAL: break; - case TAG_KEEP_REMOTE: - case TAG_MERGE: { - printf("skip update: %s\n", local->path); - update_tags = FALSE; - break; - } - } - } - - // TODO: free remote_tags + if(tag_data) { + char *hash = dav_create_hash(tag_data->space, tag_data->size); + local->tags_hash = hash; } - } - - if(update_tags) { - DavXmlNode *prop = create_xml_taglist(tags); - if(prop) { - dav_set_property_ns(res, DAV_NS, "tags", prop); - if(dav_store(res)) { - print_resource_error(sn, local->path); - } - } + local->tags_updated = FALSE; } // TODO: free stuff