fix dav-sync push not deleting collections in the right order

Mon, 12 Jun 2023 21:40:31 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 12 Jun 2023 21:40:31 +0200
changeset 760
ae759e4be591
parent 759
a3e35cae098b
child 761
a2f1d7c1755c

fix dav-sync push not deleting collections in the right order

dav/sync.c file | annotate | diff | comparison | revisions
--- a/dav/sync.c	Mon Jun 12 21:17:37 2023 +0200
+++ b/dav/sync.c	Mon Jun 12 21:40:31 2023 +0200
@@ -476,6 +476,14 @@
     return ret;
 }
 
+static int localres_cmp_path(LocalResource *a, LocalResource *b, void *n) {
+    return strcmp(a->path, b->path);
+}
+
+static int localres_cmp_path_desc(LocalResource *a, LocalResource *b, void *n) {
+    return -strcmp(a->path, b->path);
+}
+
 static DavSession* create_session(CmdArgs *a, DavContext *ctx, Repository *repo, char *collection) {
     int flags = get_repository_flags(repo);
     DavBool find_collection = TRUE;
@@ -2419,7 +2427,8 @@
     // delete all removed files
     cxListSort(ls_delete);
     
-    CxList *cols = cxLinkedListCreateSimple(CX_STORE_POINTERS);
+    CxList *cols = cxLinkedListCreate(cxDefaultAllocator, (cx_compare_func)localres_cmp_path_desc, CX_STORE_POINTERS);
+    CxList *cols_del = cols; // remember pointer for cleanup
     CxList *col_list = cols;
     CxList *deletelist = ls_delete;
     for(int i=0;i<2;i++) {
@@ -2445,9 +2454,12 @@
                 //local_resource_free(dbres);
             }
         }
+        cxListSort(cols);
         deletelist = cols;
         col_list = NULL;
-    }   
+    }
+    
+    cxListDestroy(cols_del);
     
     // unlock repository
     if(locked) {
@@ -2490,10 +2502,6 @@
     return ret;
 }
 
-static int localres_cmp_path(LocalResource *a, LocalResource *b, void *n) {
-    return strcmp(a->path, b->path);
-}
-
 int cmd_restore(CmdArgs *a) {
     char *syncdir = cmd_getoption(a, "syncdir");
     

mercurial