Fri, 12 Apr 2019 10:54:47 +0200
replace list of removed resources with a map (cmd_pull)
dav/sync.c | file | annotate | diff | comparison | revisions |
--- a/dav/sync.c Wed Apr 10 13:50:24 2019 +0200 +++ b/dav/sync.c Fri Apr 12 10:54:47 2019 +0200 @@ -587,11 +587,13 @@ UcxList *res_modified = NULL; UcxList *res_new = NULL; + UcxList *res_moved = NULL; + UcxList *res_copied = NULL; UcxList *res_conflict = NULL; UcxList *res_mkdir = NULL; UcxList *res_metadata = NULL; UcxList *res_broken = NULL; - UcxList *lres_removed = NULL; // list of LocalResource* + UcxMap *lres_removed = ucx_map_new(16); // contains LocalResource* //UcxMap *svrres = ucx_map_new(db->resources->count); UcxMap *dbres = ucx_map_clone(db->resources, NULL, NULL); @@ -686,7 +688,10 @@ continue; } if(!local->keep) { - lres_removed = ucx_list_prepend(lres_removed, local); + ucx_map_cstr_put(lres_removed, local->path, local); + if(lres_removed->count > lres_removed->size * 2) { + ucx_map_rehash(lres_removed); + } } } @@ -705,7 +710,7 @@ // we need a map for all conflicts for fast lookups UcxMap *conflicts = ucx_map_new(ucx_list_size(res_conflict)+16); UCX_FOREACH(elm, res_conflict) { - ++sync_conflict; + sync_conflict++; DavResource *res = elm->data; ucx_map_cstr_put(conflicts, res->path, res); } @@ -762,23 +767,26 @@ } UcxList *rmdirs = NULL; - UCX_FOREACH(elm, lres_removed) { - LocalResource *res = elm->data; + UcxMapIterator mi = ucx_map_iterator(lres_removed); + LocalResource *removed_res; + UcxKey key; + UCX_MAP_FOREACH(key, removed_res, mi) { if(sync_shutdown) { break; } - int ret = sync_remove_local_resource(dir, res); + int ret = sync_remove_local_resource(dir, removed_res); if(ret == -1) { - rmdirs = ucx_list_append(rmdirs, res); + rmdirs = ucx_list_append(rmdirs, removed_res); } else if(ret == 0) { - LocalResource *local = ucx_map_cstr_remove(db->resources, res->path); + LocalResource *local = ucx_map_cstr_remove(db->resources, removed_res->path); if(local) { local_resource_free(local); } sync_delete++; } } + ucx_map_free(lres_removed); UCX_FOREACH(elm, rmdirs) { LocalResource *local_dir = elm->data; @@ -1736,7 +1744,7 @@ nullfree(local_res->hash); local_res->hash = NULL; local_res->skipped = TRUE; - ++sync_conflict; + sync_conflict++; } else { printf("put: %s\n", local_res->path); if(sync_put_resource(dir, res, local_res, &sync_success)) { @@ -1772,7 +1780,7 @@ nullfree(local->hash); local->hash = NULL; local->skipped = TRUE; - ++sync_conflict; + sync_conflict++; } else { DavResource *origin_res = dav_resource_new(sn, local->origin->path); int origin_changed = remote_resource_is_changed(