fixes crash when dav-sync push can't delete a resource on the server v1.0

Sun, 10 Sep 2017 10:37:51 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 10 Sep 2017 10:37:51 +0200
branch
v1.0
changeset 303
5d79c108fcab
parent 301
cbea102875a8
child 310
9a0a06637f91

fixes crash when dav-sync push can't delete a resource on the server

dav/sync.c file | annotate | diff | comparison | revisions
dav/sync.h file | annotate | diff | comparison | revisions
--- a/dav/sync.c	Thu Sep 07 18:42:51 2017 +0200
+++ b/dav/sync.c	Sun Sep 10 10:37:51 2017 +0200
@@ -865,7 +865,7 @@
         UCX_MAP_FOREACH(key, local, i) {
             if (!res_matches_filter(dir, local->path+1)) {
                 if(sync_delete_remote_resource(sn, local, &sync_delete)) {
-                    ucx_map_cstr_put(lclres, local->path, local);
+                    ucx_map_cstr_put(lclres, local->path, local_resource_copy(local));
                     if(sn->error != DAV_NOT_FOUND) {
                         print_resource_error(sn, local->path);
                         sync_error++;
@@ -1040,6 +1040,24 @@
     }
 }
 
+LocalResource* local_resource_copy(LocalResource *res) {
+    LocalResource *newres = calloc(1, sizeof(LocalResource));
+    if(res->name) {
+        newres->name = strdup(res->name);
+    }
+    if(res->path) {
+        newres->path = strdup(res->path);
+    }
+    if(res->etag) {
+        newres->etag = strdup(res->etag);
+    }
+    newres->skipped = res->skipped;
+    newres->size = res->size;
+    newres->last_modified = res->last_modified;
+    newres->isdirectory = res->isdirectory;
+    return newres;
+}
+
 int local_resource_is_changed(SyncDirectory *dir, SyncDatabase *db, LocalResource *res) {
     LocalResource *db_res = ucx_map_cstr_get(db->resources, res->path);
     if(db_res) {
--- a/dav/sync.h	Thu Sep 07 18:42:51 2017 +0200
+++ b/dav/sync.h	Sun Sep 10 10:37:51 2017 +0200
@@ -62,6 +62,7 @@
 UcxList* local_scan(SyncDirectory *dir, SyncDatabase *db);
 UcxList* read_changes(SyncDirectory *dir, SyncDatabase *db);
 LocalResource* local_resource_new(SyncDirectory *dir, SyncDatabase *db, char *path, int *isdir);
+LocalResource* local_resource_copy(LocalResource *res);
 int local_resource_is_changed(SyncDirectory *dir, SyncDatabase *db, LocalResource *res);
 int remote_resource_is_changed(
         DavSession *sn,

mercurial