dav/sync.c

changeset 667
6cdcd3e4e368
parent 663
888aa263c0f1
child 668
6df5ebb00841
--- 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);

mercurial