585 int sync_error = 0; |
585 int sync_error = 0; |
586 int sync_conflict = 0; |
586 int sync_conflict = 0; |
587 |
587 |
588 UcxList *res_modified = NULL; |
588 UcxList *res_modified = NULL; |
589 UcxList *res_new = NULL; |
589 UcxList *res_new = NULL; |
|
590 UcxList *res_moved = NULL; |
|
591 UcxList *res_copied = NULL; |
590 UcxList *res_conflict = NULL; |
592 UcxList *res_conflict = NULL; |
591 UcxList *res_mkdir = NULL; |
593 UcxList *res_mkdir = NULL; |
592 UcxList *res_metadata = NULL; |
594 UcxList *res_metadata = NULL; |
593 UcxList *res_broken = NULL; |
595 UcxList *res_broken = NULL; |
594 UcxList *lres_removed = NULL; // list of LocalResource* |
596 UcxMap *lres_removed = ucx_map_new(16); // contains LocalResource* |
595 |
597 |
596 //UcxMap *svrres = ucx_map_new(db->resources->count); |
598 //UcxMap *svrres = ucx_map_new(db->resources->count); |
597 UcxMap *dbres = ucx_map_clone(db->resources, NULL, NULL); |
599 UcxMap *dbres = ucx_map_clone(db->resources, NULL, NULL); |
598 |
600 |
599 UcxList *stack = ucx_list_prepend(NULL, ls->children); |
601 UcxList *stack = ucx_list_prepend(NULL, ls->children); |
684 UCX_MAP_FOREACH(key, local, i) { |
686 UCX_MAP_FOREACH(key, local, i) { |
685 if (res_matches_filter(dir, local->path)) { |
687 if (res_matches_filter(dir, local->path)) { |
686 continue; |
688 continue; |
687 } |
689 } |
688 if(!local->keep) { |
690 if(!local->keep) { |
689 lres_removed = ucx_list_prepend(lres_removed, local); |
691 ucx_map_cstr_put(lres_removed, local->path, local); |
|
692 if(lres_removed->count > lres_removed->size * 2) { |
|
693 ucx_map_rehash(lres_removed); |
|
694 } |
690 } |
695 } |
691 } |
696 } |
692 |
697 |
693 // the first thing we need are all directories to put the files in |
698 // the first thing we need are all directories to put the files in |
694 UCX_FOREACH(elm, res_mkdir) { |
699 UCX_FOREACH(elm, res_mkdir) { |
703 } |
708 } |
704 |
709 |
705 // we need a map for all conflicts for fast lookups |
710 // we need a map for all conflicts for fast lookups |
706 UcxMap *conflicts = ucx_map_new(ucx_list_size(res_conflict)+16); |
711 UcxMap *conflicts = ucx_map_new(ucx_list_size(res_conflict)+16); |
707 UCX_FOREACH(elm, res_conflict) { |
712 UCX_FOREACH(elm, res_conflict) { |
708 ++sync_conflict; |
713 sync_conflict++; |
709 DavResource *res = elm->data; |
714 DavResource *res = elm->data; |
710 ucx_map_cstr_put(conflicts, res->path, res); |
715 ucx_map_cstr_put(conflicts, res->path, res); |
711 } |
716 } |
712 |
717 |
713 // download all new, modified and conflict files |
718 // download all new, modified and conflict files |
760 res->path); |
765 res->path); |
761 } |
766 } |
762 } |
767 } |
763 |
768 |
764 UcxList *rmdirs = NULL; |
769 UcxList *rmdirs = NULL; |
765 UCX_FOREACH(elm, lres_removed) { |
770 UcxMapIterator mi = ucx_map_iterator(lres_removed); |
766 LocalResource *res = elm->data; |
771 LocalResource *removed_res; |
|
772 UcxKey key; |
|
773 UCX_MAP_FOREACH(key, removed_res, mi) { |
767 if(sync_shutdown) { |
774 if(sync_shutdown) { |
768 break; |
775 break; |
769 } |
776 } |
770 |
777 |
771 int ret = sync_remove_local_resource(dir, res); |
778 int ret = sync_remove_local_resource(dir, removed_res); |
772 if(ret == -1) { |
779 if(ret == -1) { |
773 rmdirs = ucx_list_append(rmdirs, res); |
780 rmdirs = ucx_list_append(rmdirs, removed_res); |
774 } else if(ret == 0) { |
781 } else if(ret == 0) { |
775 LocalResource *local = ucx_map_cstr_remove(db->resources, res->path); |
782 LocalResource *local = ucx_map_cstr_remove(db->resources, removed_res->path); |
776 if(local) { |
783 if(local) { |
777 local_resource_free(local); |
784 local_resource_free(local); |
778 } |
785 } |
779 sync_delete++; |
786 sync_delete++; |
780 } |
787 } |
781 } |
788 } |
|
789 ucx_map_free(lres_removed); |
782 |
790 |
783 UCX_FOREACH(elm, rmdirs) { |
791 UCX_FOREACH(elm, rmdirs) { |
784 LocalResource *local_dir = elm->data; |
792 LocalResource *local_dir = elm->data; |
785 if(!sync_remove_local_directory(dir, local_dir)) { |
793 if(!sync_remove_local_directory(dir, local_dir)) { |
786 LocalResource *local = ucx_map_cstr_remove(db->resources, local_dir->path); |
794 LocalResource *local = ucx_map_cstr_remove(db->resources, local_dir->path); |
1734 nullfree(local_res->etag); |
1742 nullfree(local_res->etag); |
1735 local_res->etag = NULL; |
1743 local_res->etag = NULL; |
1736 nullfree(local_res->hash); |
1744 nullfree(local_res->hash); |
1737 local_res->hash = NULL; |
1745 local_res->hash = NULL; |
1738 local_res->skipped = TRUE; |
1746 local_res->skipped = TRUE; |
1739 ++sync_conflict; |
1747 sync_conflict++; |
1740 } else { |
1748 } else { |
1741 printf("put: %s\n", local_res->path); |
1749 printf("put: %s\n", local_res->path); |
1742 if(sync_put_resource(dir, res, local_res, &sync_success)) { |
1750 if(sync_put_resource(dir, res, local_res, &sync_success)) { |
1743 sync_error++; |
1751 sync_error++; |
1744 print_resource_error(sn, res->path); |
1752 print_resource_error(sn, res->path); |
1770 nullfree(local->etag); |
1778 nullfree(local->etag); |
1771 local->etag = NULL; |
1779 local->etag = NULL; |
1772 nullfree(local->hash); |
1780 nullfree(local->hash); |
1773 local->hash = NULL; |
1781 local->hash = NULL; |
1774 local->skipped = TRUE; |
1782 local->skipped = TRUE; |
1775 ++sync_conflict; |
1783 sync_conflict++; |
1776 } else { |
1784 } else { |
1777 DavResource *origin_res = dav_resource_new(sn, local->origin->path); |
1785 DavResource *origin_res = dav_resource_new(sn, local->origin->path); |
1778 int origin_changed = remote_resource_is_changed( |
1786 int origin_changed = remote_resource_is_changed( |
1779 sn, |
1787 sn, |
1780 dir, |
1788 dir, |