create collections before doing other stuff on dav-sync push

Sun, 21 Apr 2019 11:27:06 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 21 Apr 2019 11:27:06 +0200
changeset 585
41368a355222
parent 584
7fb81fd429b2
child 586
b45719a52ea6

create collections before doing other stuff on dav-sync push

dav/sync.c file | annotate | diff | comparison | revisions
--- a/dav/sync.c	Sun Apr 21 11:06:16 2019 +0200
+++ b/dav/sync.c	Sun Apr 21 11:27:06 2019 +0200
@@ -1741,6 +1741,7 @@
     UcxList *ls_delete = NULL;
     UcxList *ls_move = NULL;
     UcxList *ls_copy = NULL;
+    UcxList *ls_mkcol = NULL;
     
     // upload all changed files
     //UcxList *resources = cmd_getoption(a, "read") ?
@@ -1795,7 +1796,9 @@
                     restore_removed,
                     restore_modified);
         if(is_changed) {
-            if(local_res->isnew) {
+            if(local_res->isdirectory) {
+                ls_mkcol = ucx_list_append(ls_mkcol, local_res);
+            } else if(local_res->isnew) {
                 ls_new = ucx_list_append(ls_new, local_res);
             } else {
                 ls_modified = ucx_list_append(ls_modified, local_res);
@@ -1893,6 +1896,50 @@
     int ret = 0;
     int error = 0;
     
+    // create collections
+    for(UcxList *elm=ls_mkcol;elm && !sync_shutdown;elm=elm->next) {
+        LocalResource *local_res = elm->data;
+        
+        DavResource *res = dav_resource_new(sn, local_res->path);
+        if(!res) {
+            print_resource_error(sn, local_res->path);
+            ret = -1;
+            sync_error++;
+        }
+        
+        int abort = 0;
+        
+        dav_exists(res);
+        if(sn->error == DAV_NOT_FOUND) {
+            // create collection
+            // TODO: show 405
+            printf("mkcol: %s\n", local_res->path);
+            if(sync_mkdir(dir, res, local_res) && sn->error != DAV_METHOD_NOT_ALLOWED) {
+                print_resource_error(sn, res->path);
+                ret = -1;
+                sync_error++;
+                error = 1;
+                abort = 1;
+            }
+        } else if(sn->error != DAV_OK) {
+            // dav_exists() failed
+            print_resource_error(sn, local_res->path);
+            ret = -1;
+            sync_error++;
+            error = 1;
+            abort = 1;
+        }
+        
+        if(local_res->metadata_updated && !abort) {
+            sync_update_metadata(dir, sn, res, local_res);
+        }
+        
+        dav_resource_free(res);
+        
+        LocalResource *dbres = ucx_map_cstr_remove(db->resources, local_res->path);
+        ucx_map_cstr_put(db->resources, local_res->path, local_res);
+    }
+    
     // copy/move files
     DavBool copy = TRUE;
     if(!ls_copy) {
@@ -1966,61 +2013,33 @@
             sync_error++;
         }
         
-        if(local_res->isdirectory) {
-            dav_exists(res);
-            if(sn->error == DAV_NOT_FOUND) {
-                int abort = 0;
-                // make sure to store tags for newly created cols
-                local_res->tags_updated = 1;
-                // create collection
-                // TODO: show 405
-                printf("mkcol: %s\n", local_res->path);
-                if(sync_mkdir(dir, res, local_res) && sn->error != DAV_METHOD_NOT_ALLOWED) {
-                    print_resource_error(sn, res->path);
-                    ret = -1;
-                    sync_error++;
-                    error = 1;
-                    abort = 1;
-                }
-
-                if(local_res->metadata_updated && !abort) {
-                    sync_update_metadata(dir, sn, res, local_res);
-                }
-            } else if(sn->error != DAV_OK) {
-                // dav_exists() failed
-                print_resource_error(sn, local_res->path);
+        int changed = remote_resource_is_changed(sn, dir, db, res, local_res);
+        if(cdt && changed) {
+            printf("conflict: %s\n", local_res->path);
+            local_res->last_modified = 0;
+            nullfree(local_res->etag);
+            local_res->etag = NULL;
+            nullfree(local_res->hash);
+            local_res->hash = NULL;
+            local_res->skipped = TRUE;
+            sync_conflict++;
+        } else {
+            if(local_res->link_target) {
+                printf(
+                        "link: %s -> %s\n",
+                        local_res->path,
+                        local_res->link_target);
+            } else {
+                printf("put: %s\n", local_res->path);
+            }
+            if(sync_put_resource(dir, res, local_res, &sync_success)) {
+                sync_error++;
+                print_resource_error(sn, res->path);
                 ret = -1;
-                sync_error++;
                 error = 1;
             }
-        } else {
-            int changed = remote_resource_is_changed(sn, dir, db, res, local_res);
-            if(cdt && changed) {
-                printf("conflict: %s\n", local_res->path);
-                local_res->last_modified = 0;
-                nullfree(local_res->etag);
-                local_res->etag = NULL;
-                nullfree(local_res->hash);
-                local_res->hash = NULL;
-                local_res->skipped = TRUE;
-                sync_conflict++;
-            } else {
-                if(local_res->link_target) {
-                    printf(
-                            "link: %s -> %s\n",
-                            local_res->path,
-                            local_res->link_target);
-                } else {
-                    printf("put: %s\n", local_res->path);
-                }
-                if(sync_put_resource(dir, res, local_res, &sync_success)) {
-                    sync_error++;
-                    print_resource_error(sn, res->path);
-                    ret = -1;
-                    error = 1;
-                }
-            }
         }
+        
         dav_resource_free(res);
         
         LocalResource *dbres = ucx_map_cstr_remove(db->resources, local_res->path);
@@ -2034,6 +2053,7 @@
         
         DavResource *res = dav_resource_new(sn, local_res->path);       
         if(local_res->metadata_updated) {
+            printf("update: %s\n", local_res->path);
             if(!sync_update_metadata(dir, sn, res, local_res)) {
                 LocalResource *dbres = ucx_map_cstr_remove(db->resources, local_res->path);
                 ucx_map_cstr_put(db->resources, local_res->path, local_res);
@@ -3944,7 +3964,6 @@
     MetadataHashes hashes = sync_set_metadata_properties(dir, sn, res, local);
     
     int err = 0;
-    printf("update: %s\n", local->path);
     if(dav_store(res)) {
         print_resource_error(sn, local->path);
         err = 1;

mercurial