Wed, 13 Jul 2016 17:10:00 +0200
refactored load_db function
dav/db.c | file | annotate | diff | comparison | revisions | |
dav/version.h | file | annotate | diff | comparison | revisions |
--- a/dav/db.c Wed Jul 13 16:27:06 2016 +0200 +++ b/dav/db.c Wed Jul 13 17:10:00 2016 +0200 @@ -52,16 +52,16 @@ free(dav_dir); SyncDatabase *db = malloc(sizeof(SyncDatabase)); + db->resources = ucx_map_new(2048); + db->conflict = ucx_map_new(16); + xmlTextReaderPtr reader = xmlReaderForFile(db_file, NULL, 0); if(!reader) { xmlDoc *doc = doc = xmlNewDoc(BAD_CAST "1.0"); xmlNode *root = xmlNewNode(NULL, BAD_CAST "directory"); xmlDocSetRootElement(doc, root); - if(xmlSaveFormatFileEnc(db_file, doc, "UTF-8", 1) != -1) { - db->resources = ucx_map_new(2048); - db->conflict = ucx_map_new(16); - } else { - free(db); + if(!xmlSaveFormatFileEnc(db_file, doc, "UTF-8", 1) != -1) { + destroy_db(db); db = NULL; } xmlFreeDoc(doc); @@ -70,8 +70,6 @@ } free(db_file); - db->resources = ucx_map_new(2048); - db->conflict = ucx_map_new(16); int error = 0; while(xmlTextReaderRead(reader)) { int type = xmlTextReaderNodeType(reader); @@ -100,7 +98,7 @@ xmlFreeTextReader(reader); if(error) { - // TODO: free resources and map + destroy_db(db); return NULL; } else { return db;