350 } |
350 } |
351 |
351 |
352 // store db |
352 // store db |
353 if(store_db(db, dir->database)) { |
353 if(store_db(db, dir->database)) { |
354 fprintf(stderr, "Cannot store sync db\n"); |
354 fprintf(stderr, "Cannot store sync db\n"); |
355 ret = -1; |
355 ret = -2; |
356 } |
356 } |
357 |
357 |
358 // TODO: cleanup - BUT DONT CLEANUP SYNC CONFIG (do this in main!) |
358 // TODO: cleanup |
359 dav_session_destroy(sn); |
359 dav_session_destroy(sn); |
360 |
360 |
361 // Report |
361 // Report |
362 if(ret == 0) { |
362 if(ret != -2) { |
363 char *str_success = sync_success == 1 ? "file" : "files"; |
363 char *str_success = sync_success == 1 ? "file" : "files"; |
364 char *str_delete = sync_delete == 1 ? "file" : "files"; |
364 char *str_delete = sync_delete == 1 ? "file" : "files"; |
365 char *str_error = sync_error == 1 ? "error" : "errors"; |
365 char *str_error = sync_error == 1 ? "error" : "errors"; |
366 printf("Result: %d %s pulled, %d %s deleted, %d %s\n", |
366 printf("Result: %d %s pulled, %d %s deleted, %d %s\n", |
367 sync_success, str_success, |
367 sync_success, str_success, |
751 LocalResource *local_res = elm->data; |
751 LocalResource *local_res = elm->data; |
752 if (!res_matches_filter(dir, local_res->path+1)) { |
752 if (!res_matches_filter(dir, local_res->path+1)) { |
753 if(res_isconflict(db, local_res)) { |
753 if(res_isconflict(db, local_res)) { |
754 printf("skip: %s\n", local_res->path); |
754 printf("skip: %s\n", local_res->path); |
755 sync_skipped++; |
755 sync_skipped++; |
756 local_resource_free(local_res); |
|
757 continue; |
756 continue; |
758 } |
757 } |
759 |
758 |
760 // upload every changed file |
759 // upload every changed file |
|
760 int error = 0; |
761 if (local_resource_is_changed(dir, db, local_res)) { |
761 if (local_resource_is_changed(dir, db, local_res)) { |
762 DavResource *res = dav_resource_new(sn, local_res->path); |
762 DavResource *res = dav_resource_new(sn, local_res->path); |
763 if(!res) { |
763 if(!res) { |
764 print_resource_error(sn, local_res->path); |
764 print_resource_error(sn, local_res->path); |
765 ret = -1; |
765 ret = -1; |
775 } |
775 } |
776 } else { |
776 } else { |
777 if(cdt && remote_resource_is_changed(sn, dir, db, local_res)) { |
777 if(cdt && remote_resource_is_changed(sn, dir, db, local_res)) { |
778 printf("conflict: %s\n", local_res->path); |
778 printf("conflict: %s\n", local_res->path); |
779 sync_skipped++; |
779 sync_skipped++; |
780 local_resource_free(local_res); |
|
781 continue; |
780 continue; |
782 } |
781 } |
783 |
782 |
784 printf("put: %s\n", local_res->path); |
783 printf("put: %s\n", local_res->path); |
785 if(sync_put_resource(dir, res, local_res, &sync_success)) { |
784 if(sync_put_resource(dir, res, local_res, &sync_success)) { |
786 sync_error++; |
785 sync_error++; |
787 print_resource_error(sn, res->path); |
786 print_resource_error(sn, res->path); |
788 ret = -1; |
787 ret = -1; |
789 sync_error++; |
788 sync_error++; |
|
789 error = 1; |
790 } |
790 } |
791 } |
791 } |
792 dav_resource_free(res); |
792 dav_resource_free(res); |
793 } |
793 } |
794 |
794 |
795 // remove every locally available resource from db->resource |
795 // remove every locally available resource from db->resource |
796 // the remaining elements are all deleted files |
796 // the remaining elements are all deleted files |
797 ucx_map_cstr_put(lclres, local_res->path, local_res); |
797 elm->data = NULL; |
|
798 if(!error) { |
|
799 ucx_map_cstr_put(lclres, local_res->path, local_res); |
|
800 } |
|
801 |
798 LocalResource *lr = ucx_map_cstr_remove(db->resources, local_res->path); |
802 LocalResource *lr = ucx_map_cstr_remove(db->resources, local_res->path); |
799 if(lr) { |
803 if(lr) { |
800 local_resource_free(lr); |
804 local_resource_free(lr); |
801 } |
805 } |
802 } |
806 } |
803 } |
807 } |
804 ucx_list_free(resources); |
|
805 |
808 |
806 // delete all removed files |
809 // delete all removed files |
807 if(ret == 0) { |
810 if(ret == 0) { |
808 UcxMapIterator i = ucx_map_iterator(db->resources); |
811 UcxMapIterator i = ucx_map_iterator(db->resources); |
809 LocalResource *local; |
812 LocalResource *local; |
832 } |
836 } |
833 |
837 |
834 // store db |
838 // store db |
835 if(store_db(db, dir->database)) { |
839 if(store_db(db, dir->database)) { |
836 fprintf(stderr, "Cannot store sync db\n"); |
840 fprintf(stderr, "Cannot store sync db\n"); |
837 ret = -1; |
841 ret = -2; |
838 } |
842 } |
839 |
843 |
840 // cleanup |
844 // cleanup |
841 dav_session_destroy(sn); |
845 dav_session_destroy(sn); |
842 ucx_list_free(resources); // content is already freed |
846 while(resources) { |
|
847 UcxList *next = resources->next; |
|
848 if(resources->data) { |
|
849 local_resource_free(resources->data); |
|
850 } |
|
851 free(resources); |
|
852 resources = next; |
|
853 } |
843 |
854 |
844 // Report |
855 // Report |
845 if(ret == 0) { |
856 if(ret != -2) { |
846 char *str_success = sync_success == 1 ? "file" : "files"; |
857 char *str_success = sync_success == 1 ? "file" : "files"; |
847 char *str_delete = sync_delete == 1 ? "file" : "files"; |
858 char *str_delete = sync_delete == 1 ? "file" : "files"; |
848 char *str_skipped = sync_delete == 1 ? "file" : "files"; |
859 char *str_skipped = sync_delete == 1 ? "file" : "files"; |
849 char *str_error = sync_error == 1 ? "error" : "errors"; |
860 char *str_error = sync_error == 1 ? "error" : "errors"; |
850 printf("Result: %d %s pushed, %d %s deleted, %d %s skipped, %d %s\n", |
861 printf("Result: %d %s pushed, %d %s deleted, %d %s skipped, %d %s\n", |