Sun, 20 Oct 2019 11:11:22 +0200
finish basic metadata sync tests
--- a/dav/db.c Sun Oct 20 10:35:02 2019 +0200 +++ b/dav/db.c Sun Oct 20 11:11:22 2019 +0200 @@ -538,6 +538,18 @@ } } + 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->link_target) { r = xmlTextWriterWriteElement( writer,
--- a/dav/sync.c Sun Oct 20 10:35:02 2019 +0200 +++ b/dav/sync.c Sun Oct 20 11:11:22 2019 +0200 @@ -3313,12 +3313,13 @@ return 0; } + char *remote_hash = NULL; UcxList *tags = NULL; if(dir->tagconfig) { DavXmlNode *tagsprop = dav_get_property_ns(res, DAV_PROPS_NS, "tags"); if(tagsprop) { tags = parse_dav_xml_taglist(tagsprop); - + remote_hash = create_tags_hash(tags); } } @@ -3362,6 +3363,12 @@ } int ret = sync_store_tags_local(dir, local, path, tags); + if(!ret) { + if(local->remote_tags_hash) { + free(local->remote_tags_hash); + } + local->remote_tags_hash = remote_hash; + } // TODO: free stuff @@ -4235,23 +4242,29 @@ LocalResource *local) { MetadataHashes hashes = {NULL, NULL, NULL, 0, 0, 0}; - if(dir->tagconfig) { + if(dir->tagconfig) { // get local tags DavBool changed = 0; char *tags_hash = NULL; UcxList *tags = sync_get_file_tags(dir, local, &changed, &tags_hash); - if(changed || local->tags_updated) { - hashes.tags = tags_hash; - hashes.update_tags = 1; + char *new_remote_hash = nullstrdup(tags_hash); + if(changed || local->tags_updated) { + DavBool store_tags = TRUE; - DavBool store_tags = TRUE; // get remote tags + DavPropName p; + p.ns = DAV_PROPS_NS; + p.name = "tags"; + if(dav_load_prop(res, &p, 1) && sn->error != DAV_NOT_FOUND) { + print_resource_error(sn, res->path); + } UcxList *remote_tags = NULL; DavXmlNode *tagsprop = dav_get_property_ns(res, DAV_PROPS_NS, "tags"); if(tagsprop) { remote_tags = parse_dav_xml_taglist(tagsprop); } char *remote_hash = create_tags_hash(remote_tags); + if(nullstrcmp(remote_hash, local->remote_tags_hash)) { // the tags have changed on the server switch(dir->tagconfig->conflict) { @@ -4266,10 +4279,17 @@ UcxList *new_tags = merge_tags(tags, remote_tags); free_taglist(tags); tags = new_tags; + + nullfree(tags_hash); + nullfree(new_remote_hash); + tags_hash = create_tags_hash(tags); + new_remote_hash = nullstrdup(tags_hash); + break; } } } + nullfree(remote_hash); if(dir->tagconfig->local_format == TAG_FORMAT_CSV) { // csv tag lists don't have colors, so we have to add @@ -4284,6 +4304,11 @@ } else { dav_remove_property_ns(res, DAV_PROPS_NS, "tags"); } + + hashes.tags = tags_hash; + hashes.update_tags = 1; + hashes.tags_remote = new_remote_hash; + hashes.update_tags_remote = 1; } free_taglist(remote_tags);
--- a/dav/tags.c Sun Oct 20 10:35:02 2019 +0200 +++ b/dav/tags.c Sun Oct 20 11:11:22 2019 +0200 @@ -168,7 +168,7 @@ if(c->type == DAV_XML_ELEMENT) { char *value = dav_xml_getstring(c->children); if(value) { - if(!strcmp(c->namespace, DAV_NS)) { + if(!strcmp(c->namespace, DAV_PROPS_NS)) { if(!strcmp(c->name, "name")) { char *value = dav_xml_getstring(c->children); if(value) { @@ -202,7 +202,7 @@ DavXmlNode *node = taglistnode; while(node) { if(node->type == DAV_XML_ELEMENT) { - if(!strcmp(node->namespace, DAV_NS) && !strcmp(node->name, "tag")) { + if(!strcmp(node->namespace, DAV_PROPS_NS) && !strcmp(node->name, "tag")) { DavTag *tag = parse_xml_dav_tag(node); if(tag) { tags = ucx_list_append(tags, tag); @@ -221,11 +221,11 @@ UCX_FOREACH(elm, tags) { DavTag *tag = elm->data; - DavXmlNode *tagelm = dav_xml_createnode(DAV_NS, "tag"); - DavXmlNode *tagname = dav_xml_createnode_with_text(DAV_NS, "name", tag->name); + DavXmlNode *tagelm = dav_xml_createnode(DAV_PROPS_NS, "tag"); + DavXmlNode *tagname = dav_xml_createnode_with_text(DAV_PROPS_NS, "name", tag->name); tagelm->children = tagname; if(tag->color) { - DavXmlNode *tagcolor = dav_xml_createnode_with_text(DAV_NS, "color", tag->color); + DavXmlNode *tagcolor = dav_xml_createnode_with_text(DAV_PROPS_NS, "color", tag->color); tagname->next = tagcolor; }
--- a/test/bin-test/dav-home/sync.xml Sun Oct 20 10:35:02 2019 +0200 +++ b/test/bin-test/dav-home/sync.xml Sun Oct 20 11:11:22 2019 +0200 @@ -124,6 +124,8 @@ <tagconfig> <local-store format="csv">xattr</local-store> + <detect-changes>true</detect-changes> + <on-conflict>merge</on-conflict> </tagconfig> <metadata>all</metadata> </directory> @@ -140,6 +142,8 @@ <tagconfig> <local-store format="csv">xattr</local-store> + <detect-changes>true</detect-changes> + <on-conflict>merge</on-conflict> </tagconfig> <metadata>all</metadata> </directory>
--- a/test/bin-test/test-dav-sync-metadata1.sh Sun Oct 20 10:35:02 2019 +0200 +++ b/test/bin-test/test-dav-sync-metadata1.sh Sun Oct 20 11:11:22 2019 +0200 @@ -397,7 +397,7 @@ check_tmpout "0 errors" "test 9: wrong error counter (push)" LN=`cat tmp-sync/out.txt | wc -l` if [ "$LN" != "1" ]; then - echo "test 7: wrong output (push)" + echo "test 9: wrong output (push)" exit 2 fi @@ -411,6 +411,7 @@ exit 2 fi + # ---------------------------------------------------------------------------- # test 10: add tags to files and sync # expected result: tags synced @@ -448,3 +449,89 @@ $DAV_SYNC_BIN list-tags -s test4b tmp-sync/test4b/dir1/file2 > tmp-sync/out.txt check_tmpout "test" "test 10: file2 missing tag" + +# ---------------------------------------------------------------------------- +# test 11: check if double update happens +# expected result: nothing happens + +dav_sync_push test4a "test 11: push failed" +check_tmpout "0 files pushed" "test 11: wrong push counter" +check_tmpout "0 conflicts" "test 11: wrong conflict counter (push)" +check_tmpout "0 errors" "test 11: wrong error counter (push)" +LN=`cat tmp-sync/out.txt | wc -l` +if [ "$LN" != "1" ]; then + echo "test 11: wrong output (push)" + exit 2 +fi + +dav_sync_pull test4b "test 11: pull failed" +check_tmpout "0 files pulled" "test 11: wrong pull counter" +check_tmpout "0 conflicts" "test 11: wrong conflict counter (pull)" +check_tmpout "0 errors" "test 11: wrong error counter (pull)" +LN=`cat tmp-sync/out.txt | wc -l` +if [ "$LN" != "1" ]; then + echo "test 11: wrong output (pull)" + exit 2 +fi + + +# ---------------------------------------------------------------------------- +# test 12: add tag, push test4a and pull test4a +# expected result: tags pushed, nothing pulled + +$DAV_SYNC_BIN add-tag -s test4a tmp-sync/test4a/file1 work +touch -t 03011100 tmp-sync/test4a/file1 + +dav_sync_push test4a "test 12: push failed" +check_tmpout "0 conflicts" "test 12: wrong conflict counter (push)" +check_tmpout "0 errors" "test 12: wrong error counter (push)" +check_tmpout "update: /file1" "test 12: file 1 not pushed" + +dav_sync_pull test4a "test 12: pull failed" +check_tmpout "0 files pulled" "test 12: wrong pull counter" +check_tmpout "0 conflicts" "test 12: wrong conflict counter (pull)" +check_tmpout "0 errors" "test 12: wrong error counter (pull)" +LN=`cat tmp-sync/out.txt | wc -l` +if [ "$LN" != "1" ]; then + echo "test 12: wrong output (pull)" + exit 2 +fi + + +# ---------------------------------------------------------------------------- +# test 13: pull test4b +# expected result: update file1, sync tags + +dav_sync_pull test4b "test 13: pull failed" +check_tmpout "0 conflicts" "test 13: wrong conflict counter (pull)" +check_tmpout "0 errors" "test 13: wrong error counter (pull)" +check_tmpout "update: /file1" "test 13: file 1 not pulled" + +$DAV_SYNC_BIN list-tags -s test4b tmp-sync/test4b/file1 > tmp-sync/out.txt +check_tmpout "test" "test 13: file1 missing tag 'test'" +check_tmpout "work" "test 13: file1 missing tag 'work'" + + +# ---------------------------------------------------------------------------- +# test 14: remove tags from file4 and sync +# expected result: tags removed + +$DAV_SYNC_BIN remove-tag -s test4a tmp-sync/test4a/file4 test +touch -t 04011100 tmp-sync/test4a/file4 + +dav_sync_push test4a "test 14: push failed" +check_tmpout "0 conflicts" "test 14: wrong conflict counter (push)" +check_tmpout "0 errors" "test 14: wrong error counter (push)" +check_tmpout "update: /file4" "test 14: file 4 not pushed" + +dav_sync_pull test4b "test 14: pull failed" +check_tmpout "0 conflicts" "test 14: wrong conflict counter (pull)" +check_tmpout "0 errors" "test 14: wrong error counter (pull)" +check_tmpout "update: /file4" "test 14: file 4 not pulled" + +LN=`$DAV_SYNC_BIN list-tags -s test4b tmp-sync/test4b/file4 | wc -l` +if [ "$LN" != "0" ]; then + echo "test 14: wrong tag count" + exit 2 +fi +
--- a/test/bin-test/test-dav-sync.sh Sun Oct 20 10:35:02 2019 +0200 +++ b/test/bin-test/test-dav-sync.sh Sun Oct 20 11:11:22 2019 +0200 @@ -95,13 +95,13 @@ # do_test "dav-sync push (1)" test-dav-sync-push1.sh do_test "dav-sync pull (1)" test-dav-sync-pull1.sh -#do_test "dav-sync pull conflict (1)" test-dav-sync-pull-conflict.sh -#do_test "dav-sync push conflict (1)" test-dav-sync-push-conflict.sh -#do_test "dav-sync hashing (1)" test-dav-sync-hashing1.sh -#do_test "dav-sync hashing (2)" test-dav-sync-hashing1.sh -#do_test "dav-sync hash strategy" test-dav-sync-hash-strategy.sh -#do_test "dav-sync hash conflict resolution" test-dav-sync-hash-conflictres.sh -#do_test "dav-sync hashing change cfg" test-dav-sync-hashing-cfgchange.sh +do_test "dav-sync pull conflict (1)" test-dav-sync-pull-conflict.sh +do_test "dav-sync push conflict (1)" test-dav-sync-push-conflict.sh +do_test "dav-sync hashing (1)" test-dav-sync-hashing1.sh +do_test "dav-sync hashing (2)" test-dav-sync-hashing1.sh +do_test "dav-sync hash strategy" test-dav-sync-hash-strategy.sh +do_test "dav-sync hash conflict resolution" test-dav-sync-hash-conflictres.sh +do_test "dav-sync hashing change cfg" test-dav-sync-hashing-cfgchange.sh do_test "dav-sync metadata1" test-dav-sync-metadata1.sh # cleanup