dav/sync.c

changeset 224
4b55f05f4e00
parent 223
cbbdf207e67e
child 225
a297c2e28fa1
--- a/dav/sync.c	Sat Mar 19 12:34:32 2016 +0100
+++ b/dav/sync.c	Sat Mar 19 18:49:36 2016 +0100
@@ -114,11 +114,15 @@
         ret = list_syncdirs();
     }
     
-    // TODO: cleanup sync config (don't forget to call regfree for regex)
+    // cleanup
     cmd_args_free(args);
     dav_context_destroy(ctx);
     
     free_config();
+    free_sync_config();
+    
+    curl_global_cleanup();
+    xmlCleanupParser();
     
     return ret;
 }
@@ -263,22 +267,22 @@
         // TODO: free
         return -1;
     }
-    
-    int sync_success = 0;
-    int sync_delete = 0;
-    int sync_error = 0;
-    
-    if(!ls->children) {
-        // TODO: free
-        fprintf(stderr, "Repository is empty\n");
+    if(!ls->iscollection) {
+        fprintf(stderr, "%s is not a collection.\nAbort.\n", ls->path);
         if(locked) {
             if(dav_unlock(root)) {
                 print_resource_error(sn, "/");
             }
         }
-        return 0; // empty repository
+        // TODO: free
+        dav_session_destroy(sn);
+        return -1;
     }
     
+    int sync_success = 0;
+    int sync_delete = 0;
+    int sync_error = 0;
+    
     UcxMap *svrres = ucx_map_new(db->resources->count);
     
     UcxList *stack = ucx_list_prepend(NULL, ls->children);
@@ -338,6 +342,7 @@
         LocalResource *local_dir = elm->data;
         sync_remove_local_directory(dir, local_dir);
     }
+    ucx_map_free_content(db->resources, (ucx_destructor)local_resource_free);
     ucx_map_free(db->resources);
     db->resources = svrres;
     
@@ -355,7 +360,7 @@
         ret = -2;
     }
     
-    // TODO: cleanup
+    // cleanup
     dav_session_destroy(sn);
     
     // Report
@@ -551,7 +556,8 @@
     
     printf("delete: %s\n", res->path);
     if(rmdir(local_path)) {
-        // TODO
+        fprintf(stderr, "rmdir: %s : ", local_path);
+        perror(NULL);
     }
     
     free(local_path);
@@ -1247,19 +1253,21 @@
     
     // remove conflicts
     int num_conflict = db->conflict->count;
-    //TODO: ucx_map_free_content(db->conflict, destr);
+    ucx_map_free_content(db->conflict, (ucx_destructor)local_resource_free);
     ucx_map_clear(db->conflict);
     
     // store db
     if(store_db(db, dir->database)) {
         fprintf(stderr, "Cannot store sync db\n");
         fprintf(stderr, "Abort\n");
-        ret = -1;
+        ret = -2;
     }
+    
+    // cleanup
     destroy_db(db);
     
     // Report
-    if(ret == 0) {
+    if(ret != -2) {
         char *str_conflict = num_conflict == 1 ? "conflict" : "conflicts";
         printf("Result: %d %s resolved\n", num_conflict, str_conflict);
     }
@@ -1306,7 +1314,7 @@
         }
         free(path);
     }
-    //TODO: ucx_map_free_content(db->conflict, destr);
+    ucx_map_free_content(db->conflict, (ucx_destructor)local_resource_free);
     ucx_map_clear(db->conflict);
     
     // store db
@@ -1315,6 +1323,8 @@
         fprintf(stderr, "Abort\n");
         ret = -1;
     }
+    
+    // cleanup
     destroy_db(db);
     
     // Report

mercurial