dav/sync.c

changeset 760
ae759e4be591
parent 759
a3e35cae098b
child 762
098b2e3ab240
equal deleted inserted replaced
759:a3e35cae098b 760:ae759e4be591
474 CxIterator i = cxListIterator(res_tags); 474 CxIterator i = cxListIterator(res_tags);
475 cxListDestroy(res_tags); 475 cxListDestroy(res_tags);
476 return ret; 476 return ret;
477 } 477 }
478 478
479 static int localres_cmp_path(LocalResource *a, LocalResource *b, void *n) {
480 return strcmp(a->path, b->path);
481 }
482
483 static int localres_cmp_path_desc(LocalResource *a, LocalResource *b, void *n) {
484 return -strcmp(a->path, b->path);
485 }
486
479 static DavSession* create_session(CmdArgs *a, DavContext *ctx, Repository *repo, char *collection) { 487 static DavSession* create_session(CmdArgs *a, DavContext *ctx, Repository *repo, char *collection) {
480 int flags = get_repository_flags(repo); 488 int flags = get_repository_flags(repo);
481 DavBool find_collection = TRUE; 489 DavBool find_collection = TRUE;
482 if((flags & DAV_SESSION_DECRYPT_NAME) != DAV_SESSION_DECRYPT_NAME) { 490 if((flags & DAV_SESSION_DECRYPT_NAME) != DAV_SESSION_DECRYPT_NAME) {
483 char *url = util_concat_path(repo->url, collection); 491 char *url = util_concat_path(repo->url, collection);
2417 } 2425 }
2418 2426
2419 // delete all removed files 2427 // delete all removed files
2420 cxListSort(ls_delete); 2428 cxListSort(ls_delete);
2421 2429
2422 CxList *cols = cxLinkedListCreateSimple(CX_STORE_POINTERS); 2430 CxList *cols = cxLinkedListCreate(cxDefaultAllocator, (cx_compare_func)localres_cmp_path_desc, CX_STORE_POINTERS);
2431 CxList *cols_del = cols; // remember pointer for cleanup
2423 CxList *col_list = cols; 2432 CxList *col_list = cols;
2424 CxList *deletelist = ls_delete; 2433 CxList *deletelist = ls_delete;
2425 for(int i=0;i<2;i++) { 2434 for(int i=0;i<2;i++) {
2426 // the first iteration deletes everything from ls_delete except 2435 // the first iteration deletes everything from ls_delete except
2427 // all collections, which are stored in cols 2436 // all collections, which are stored in cols
2443 } else { 2452 } else {
2444 LocalResource *dbres = cxMapRemoveAndGet(db->resources, cx_hash_key_str(local->path)); 2453 LocalResource *dbres = cxMapRemoveAndGet(db->resources, cx_hash_key_str(local->path));
2445 //local_resource_free(dbres); 2454 //local_resource_free(dbres);
2446 } 2455 }
2447 } 2456 }
2457 cxListSort(cols);
2448 deletelist = cols; 2458 deletelist = cols;
2449 col_list = NULL; 2459 col_list = NULL;
2450 } 2460 }
2461
2462 cxListDestroy(cols_del);
2451 2463
2452 // unlock repository 2464 // unlock repository
2453 if(locked) { 2465 if(locked) {
2454 if(dav_unlock(root)) { 2466 if(dav_unlock(root)) {
2455 print_resource_error(sn, "/"); 2467 print_resource_error(sn, "/");
2486 printf("%d %s, %d %s\n", 2498 printf("%d %s, %d %s\n",
2487 sync_conflict, str_conflict, sync_error, str_error); 2499 sync_conflict, str_conflict, sync_error, str_error);
2488 } 2500 }
2489 2501
2490 return ret; 2502 return ret;
2491 }
2492
2493 static int localres_cmp_path(LocalResource *a, LocalResource *b, void *n) {
2494 return strcmp(a->path, b->path);
2495 } 2503 }
2496 2504
2497 int cmd_restore(CmdArgs *a) { 2505 int cmd_restore(CmdArgs *a) {
2498 char *syncdir = cmd_getoption(a, "syncdir"); 2506 char *syncdir = cmd_getoption(a, "syncdir");
2499 2507

mercurial