dav/sync.c

changeset 672
4bfe452a2665
parent 669
152101df336d
child 675
a8117c4feaad
--- a/dav/sync.c	Fri Oct 25 19:39:33 2019 +0200
+++ b/dav/sync.c	Sat Oct 26 11:32:27 2019 +0200
@@ -4005,7 +4005,7 @@
     }
     
     MetadataHashes hashes;
-    hashes = sync_set_metadata_properties(dir, res->session, res, local);
+    hashes = sync_set_metadata_properties(dir, res->session, res, local, FALSE);
     
     // before sync_put_resource, remote_resource_is_changed does a propfind
     // and sets res->exists
@@ -4135,38 +4135,37 @@
     if(!copy) {
         ucx_map_cstr_remove(db->resources, local_origin->path);
     }
-    // replace LocalResource with origin content
-    local->origin = NULL;
-    char *path = strdup(local->path);
-    // TODO: free stuff before replacing it
-    memcpy(local, local_origin, sizeof(LocalResource));
-    local->path = path;
-    
-    free(local_origin); // only free origin pointer
+    
+    // set resource metadata
+    DavResource *up_res = dav_resource_new(origin->session, local->path);
+    if(!up_res) {
+        return 1;
+    }
+    
+    sync_set_metadata_from_stat(local, &s);
+    MetadataHashes hashes;
+    hashes = sync_set_metadata_properties(dir, up_res->session, up_res, local, TRUE);
+    if(dav_store(up_res)) {
+        fprintf(stderr, "Error: cannot store resource metadata\n");
+    }
     
     // get new etag
-    DavResource *up_res = dav_get(origin->session, local->path, "D:getetag");
-    if(up_res) {
+    DavPropName p;
+    p.ns = "DAV:";
+    p.name = "getetag";
+    if(!dav_load_prop(up_res, &p, 1)) {
         (*counter)++;
         
-        // set metadata
-        MetadataHashes hashes;
-        hashes = sync_set_metadata_properties(dir, up_res->session, up_res, local);
-        if(dav_store(up_res)) {
-            fprintf(stderr, "Error: cannot store resource metadata\n");
-        }
-        
         // everything seems fine, we can update the local resource
         char *etag = dav_get_string_property(up_res, "D:getetag");
         local_resource_set_etag(local, etag);
         
         local->last_modified = s.st_mtime;
-        
-        dav_resource_free(up_res);
     } else {
         result = 1;
     }
     
+    dav_resource_free(up_res);   
     return result;
 }
 
@@ -4242,8 +4241,15 @@
         SyncDirectory *dir,
         DavSession *sn,
         DavResource *res,
-        LocalResource *local)
+        LocalResource *local,
+        DavBool force)
 {
+    if(force) {
+        local->tags_updated = 1;
+        local->finfo_updated = 1;
+        local->xattr_updated = 1;
+    }
+    
     MetadataHashes hashes = {NULL, NULL, NULL, 0, 0, 0};
     if(dir->tagconfig) {     
         // get local tags
@@ -4270,7 +4276,8 @@
             
             if(nullstrcmp(remote_hash, local->remote_tags_hash)) {
                 // the tags have changed on the server
-                switch(dir->tagconfig->conflict) {
+                int conflict_resolution = force ? TAG_NO_CONFLICT : dir->tagconfig->conflict;
+                switch(conflict_resolution) {
                     case TAG_NO_CONFLICT: break;
                     case TAG_KEEP_LOCAL: break;
                     case TAG_KEEP_REMOTE: {
@@ -4345,6 +4352,9 @@
             }
         }
     }
+    
+    local->tags_updated = 0;
+    
     return hashes;
 }
 
@@ -4354,7 +4364,7 @@
         DavResource *res,
         LocalResource *local)
 {
-    MetadataHashes hashes = sync_set_metadata_properties(dir, sn, res, local);
+    MetadataHashes hashes = sync_set_metadata_properties(dir, sn, res, local, FALSE);
     
     int err = 0;
     if(dav_store(res)) {

mercurial