Sat, 19 Mar 2016 18:49:36 +0100
added more cleanup code
dav/config.c | file | annotate | diff | comparison | revisions | |
dav/scfg.c | file | annotate | diff | comparison | revisions | |
dav/scfg.h | file | annotate | diff | comparison | revisions | |
dav/sync.c | file | annotate | diff | comparison | revisions |
--- a/dav/config.c Sat Mar 19 12:34:32 2016 +0100 +++ b/dav/config.c Sat Mar 19 18:49:36 2016 +0100 @@ -149,7 +149,7 @@ } if(repo->cert) { free(repo->cert); - } + } free(repo); } ucx_map_free(repos);
--- a/dav/scfg.c Sat Mar 19 12:34:32 2016 +0100 +++ b/dav/scfg.c Sat Mar 19 18:49:36 2016 +0100 @@ -328,3 +328,38 @@ } return dbname; } + + +void free_sync_config() { + printf("free_sync_config\n"); + UcxMapIterator i = ucx_map_iterator(directories); + SyncDirectory *dir; + UCX_MAP_FOREACH(elm, dir, i) { + free(dir->name); + free(dir->path); + free(dir->repository); + free(dir->database); + + if(dir->collection) { + free(dir->collection); + } + if(dir->trash) { + free(dir->trash); + } + + UCX_FOREACH(elm, dir->include) { + regfree(elm->data); + free(elm->data); + } + ucx_list_free(dir->include); + UCX_FOREACH(elm, dir->exclude) { + regfree(elm->data); + free(elm->data); + } + ucx_list_free(dir->exclude); + + free(dir); + } + + ucx_map_free(directories); +}
--- a/dav/scfg.h Sat Mar 19 12:34:32 2016 +0100 +++ b/dav/scfg.h Sat Mar 19 18:49:36 2016 +0100 @@ -65,6 +65,8 @@ int list_syncdirs(); char* generate_db_name(char *basename); +void free_sync_config(); + #ifdef __cplusplus }
--- 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