780:cd1c869720e0 | 781:08d887af3971 |
---|---|
669 fprintf(stderr, "Abort\n"); | 669 fprintf(stderr, "Abort\n"); |
670 return -1; | 670 return -1; |
671 } | 671 } |
672 DavLock *lock = dav_get_lock(sn, "/"); | 672 DavLock *lock = dav_get_lock(sn, "/"); |
673 if(lock) { | 673 if(lock) { |
674 printf("Lock-Token: %s\n", lock->token); | 674 log_printf("Lock-Token: %s\n", lock->token); |
675 } | 675 } |
676 locked = TRUE; | 676 locked = TRUE; |
677 locktokenfile = create_locktoken_file(dir->name, lock->token); | 677 locktokenfile = create_locktoken_file(dir->name, lock->token); |
678 } | 678 } |
679 | 679 |
956 break; | 956 break; |
957 } | 957 } |
958 | 958 |
959 LocalResource *local = cxMapGet(db->resources, cx_hash_key_str(res->path)); | 959 LocalResource *local = cxMapGet(db->resources, cx_hash_key_str(res->path)); |
960 if(local) { | 960 if(local) { |
961 printf("update: %s\n", res->path); | 961 log_printf("update: %s\n", res->path); |
962 char *res_path = resource_local_path(res); | 962 char *res_path = resource_local_path(res); |
963 char *local_path = create_local_path(dir, res->path); | 963 char *local_path = create_local_path(dir, res->path); |
964 free(res_path); | 964 free(res_path); |
965 if(sync_store_metadata(dir, local_path, local, res)) { | 965 if(sync_store_metadata(dir, local_path, local, res)) { |
966 fprintf(stderr, "Metadata update failed: %s\n", res->path); | 966 fprintf(stderr, "Metadata update failed: %s\n", res->path); |
1045 if(ret != -2) { | 1045 if(ret != -2) { |
1046 char *str_success = sync_success == 1 ? "file" : "files"; | 1046 char *str_success = sync_success == 1 ? "file" : "files"; |
1047 char *str_delete = sync_delete == 1 ? "file" : "files"; | 1047 char *str_delete = sync_delete == 1 ? "file" : "files"; |
1048 char *str_error = sync_error == 1 ? "error" : "errors"; | 1048 char *str_error = sync_error == 1 ? "error" : "errors"; |
1049 char *str_conflict = sync_conflict == 1 ? "conflict" : "conflicts"; | 1049 char *str_conflict = sync_conflict == 1 ? "conflict" : "conflicts"; |
1050 printf("Result: %d %s pulled, %d %s deleted, %d %s, %d %s\n", | 1050 log_printf("Result: %d %s pulled, %d %s deleted, %d %s, %d %s\n", |
1051 sync_success, str_success, | 1051 sync_success, str_success, |
1052 sync_delete,str_delete, | 1052 sync_delete,str_delete, |
1053 sync_conflict, str_conflict, | 1053 sync_conflict, str_conflict, |
1054 sync_error, str_error); | 1054 sync_error, str_error); |
1055 } | 1055 } |
1447 renamefunc fn = copy ? copy_file : sys_rename; | 1447 renamefunc fn = copy ? copy_file : sys_rename; |
1448 | 1448 |
1449 char *new_path = util_concat_path(dir->path, res->path); | 1449 char *new_path = util_concat_path(dir->path, res->path); |
1450 char *old_path = util_concat_path(dir->path, local_resource_path(content)); | 1450 char *old_path = util_concat_path(dir->path, local_resource_path(content)); |
1451 | 1451 |
1452 printf("%s: %s -> %s\n", copy?"copy":"move", content->path, res->path); | 1452 log_printf("%s: %s -> %s\n", copy?"copy":"move", content->path, res->path); |
1453 if(fn(old_path, new_path)) { | 1453 if(fn(old_path, new_path)) { |
1454 free(new_path); | 1454 free(new_path); |
1455 free(old_path); | 1455 free(old_path); |
1456 return 1; | 1456 return 1; |
1457 } | 1457 } |
1579 } | 1579 } |
1580 } | 1580 } |
1581 | 1581 |
1582 int64_t truncate_file = -1; | 1582 int64_t truncate_file = -1; |
1583 if(!link) { | 1583 if(!link) { |
1584 printf("get: %s\n", path); | 1584 log_printf("get: %s\n", path); |
1585 if(issplit) { | 1585 if(issplit) { |
1586 part_updates = sync_download_changed_parts(res, local, out, blocksize, &blockcount, &truncate_file, &ret); | 1586 part_updates = sync_download_changed_parts(res, local, out, blocksize, &blockcount, &truncate_file, &ret); |
1587 } else { | 1587 } else { |
1588 ret = dav_get_content(res, out, (dav_write_func)fwrite); | 1588 ret = dav_get_content(res, out, (dav_write_func)fwrite); |
1589 } | 1589 } |
1590 fclose(out); | 1590 fclose(out); |
1591 } else { | 1591 } else { |
1592 printf("link: %s -> %s\n", path, link); | 1592 log_printf("link: %s -> %s\n", path, link); |
1593 if(sys_symlink(link, local_path)) { | 1593 if(sys_symlink(link, local_path)) { |
1594 perror("symlink"); | 1594 perror("symlink"); |
1595 ret = 1; | 1595 ret = 1; |
1596 } | 1596 } |
1597 } | 1597 } |
1704 { | 1704 { |
1705 char *res_path = resource_local_path(res); | 1705 char *res_path = resource_local_path(res); |
1706 char *local_path = create_local_path(dir, res->path); | 1706 char *local_path = create_local_path(dir, res->path); |
1707 free(res_path); | 1707 free(res_path); |
1708 | 1708 |
1709 printf("get: %s\n", res->path); | 1709 log_printf("get: %s\n", res->path); |
1710 // create directory | 1710 // create directory |
1711 // ignore error if it already exists | 1711 // ignore error if it already exists |
1712 if(sys_mkdir(local_path) && errno != EEXIST) { | 1712 if(sys_mkdir(local_path) && errno != EEXIST) { |
1713 fprintf(stderr, | 1713 fprintf(stderr, |
1714 "Cannot create directory %s: %s", | 1714 "Cannot create directory %s: %s", |
1777 if(s.st_mtime != res->last_modified) { | 1777 if(s.st_mtime != res->last_modified) { |
1778 free(local_path); | 1778 free(local_path); |
1779 return -2; | 1779 return -2; |
1780 } | 1780 } |
1781 | 1781 |
1782 printf("delete: %s\n", res->path); | 1782 log_printf("delete: %s\n", res->path); |
1783 int ret = 0; | 1783 int ret = 0; |
1784 if(dir->trash) { | 1784 if(dir->trash) { |
1785 move_to_trash(dir, local_path); | 1785 move_to_trash(dir, local_path); |
1786 } else if(sys_unlink(local_path)) { | 1786 } else if(sys_unlink(local_path)) { |
1787 fprintf(stderr, "Cannot remove file %s\n", local_path); | 1787 fprintf(stderr, "Cannot remove file %s\n", local_path); |
1794 | 1794 |
1795 int sync_remove_local_directory(SyncDirectory *dir, LocalResource *res) { | 1795 int sync_remove_local_directory(SyncDirectory *dir, LocalResource *res) { |
1796 int ret = 0; | 1796 int ret = 0; |
1797 char *local_path = create_local_path(dir, res->path); | 1797 char *local_path = create_local_path(dir, res->path); |
1798 | 1798 |
1799 printf("delete: %s\n", res->path); | 1799 log_printf("delete: %s\n", res->path); |
1800 if(rmdir(local_path)) { | 1800 if(rmdir(local_path)) { |
1801 // don't print error when dirs are not empty | 1801 // don't print error when dirs are not empty |
1802 // because that can regulary happen, because the pull conflict | 1802 // because that can regulary happen, because the pull conflict |
1803 // detection can prevent files from being deleted and in this case | 1803 // detection can prevent files from being deleted and in this case |
1804 // the parent dir is not empty | 1804 // the parent dir is not empty |
1838 | 1838 |
1839 | 1839 |
1840 if(sys_stat(new_path.ptr, &s)) { | 1840 if(sys_stat(new_path.ptr, &s)) { |
1841 if(errno == ENOENT) { | 1841 if(errno == ENOENT) { |
1842 loop = 0; | 1842 loop = 0; |
1843 printf("conflict: %s\n", local_path); | 1843 log_printf("conflict: %s\n", local_path); |
1844 if(fn(local_path, new_path.ptr)) { | 1844 if(fn(local_path, new_path.ptr)) { |
1845 //printf("errno: %d\n", errno); | 1845 //printf("errno: %d\n", errno); |
1846 fprintf( | 1846 fprintf( |
1847 stderr, | 1847 stderr, |
1848 "Cannot rename file %s to %s\n", | 1848 "Cannot rename file %s to %s\n", |
2022 fprintf(stderr, "Abort\n"); | 2022 fprintf(stderr, "Abort\n"); |
2023 return -1; | 2023 return -1; |
2024 } | 2024 } |
2025 DavLock *lock = dav_get_lock(sn, "/"); | 2025 DavLock *lock = dav_get_lock(sn, "/"); |
2026 if(lock) { | 2026 if(lock) { |
2027 printf("Lock-Token: %s\n", lock->token); | 2027 log_printf("Lock-Token: %s\n", lock->token); |
2028 } | 2028 } |
2029 locked = TRUE; | 2029 locked = TRUE; |
2030 locktokenfile = create_locktoken_file(dir->name, lock->token); | 2030 locktokenfile = create_locktoken_file(dir->name, lock->token); |
2031 } | 2031 } |
2032 | 2032 |
2246 | 2246 |
2247 dav_exists(res); | 2247 dav_exists(res); |
2248 if(sn->error == DAV_NOT_FOUND) { | 2248 if(sn->error == DAV_NOT_FOUND) { |
2249 // create collection | 2249 // create collection |
2250 // TODO: show 405 | 2250 // TODO: show 405 |
2251 printf("mkcol: %s\n", local_res->path); | 2251 log_printf("mkcol: %s\n", local_res->path); |
2252 if(sync_mkdir(dir, res, local_res) && sn->error != DAV_METHOD_NOT_ALLOWED) { | 2252 if(sync_mkdir(dir, res, local_res) && sn->error != DAV_METHOD_NOT_ALLOWED) { |
2253 print_resource_error(sn, res->path); | 2253 print_resource_error(sn, res->path); |
2254 ret = -1; | 2254 ret = -1; |
2255 sync_error++; | 2255 sync_error++; |
2256 error = 1; | 2256 error = 1; |
2295 } | 2295 } |
2296 | 2296 |
2297 int err = 0; | 2297 int err = 0; |
2298 DavResource *res = dav_resource_new(sn, local->path); | 2298 DavResource *res = dav_resource_new(sn, local->path); |
2299 if(dav_exists(res)) { | 2299 if(dav_exists(res)) { |
2300 printf("conflict: %s\n", local->path); | 2300 log_printf("conflict: %s\n", local->path); |
2301 local->last_modified = 0; | 2301 local->last_modified = 0; |
2302 nullfree(local->etag); | 2302 nullfree(local->etag); |
2303 local->etag = NULL; | 2303 local->etag = NULL; |
2304 nullfree(local->hash); | 2304 nullfree(local->hash); |
2305 local->hash = NULL; | 2305 local->hash = NULL; |
2316 NULL); | 2316 NULL); |
2317 if(origin_changed) { | 2317 if(origin_changed) { |
2318 // upload with put | 2318 // upload with put |
2319 cxListInsert(ls_modified, 0, local); | 2319 cxListInsert(ls_modified, 0, local); |
2320 } else { | 2320 } else { |
2321 printf("%s: %s -> %s\n", copy ? "copy":"move", local->origin->path, local->path); | 2321 log_printf("%s: %s -> %s\n", copy ? "copy":"move", local->origin->path, local->path); |
2322 err = sync_move_remote_resource( | 2322 err = sync_move_remote_resource( |
2323 dir, | 2323 dir, |
2324 db, | 2324 db, |
2325 origin_res, | 2325 origin_res, |
2326 local, | 2326 local, |
2373 free(local_res->etag); | 2373 free(local_res->etag); |
2374 } | 2374 } |
2375 local_res->etag = strdup(etag); | 2375 local_res->etag = strdup(etag); |
2376 } | 2376 } |
2377 } else if(cdt && changed) { | 2377 } else if(cdt && changed) { |
2378 printf("conflict: %s\n", local_res->path); | 2378 log_printf("conflict: %s\n", local_res->path); |
2379 local_res->last_modified = 0; | 2379 local_res->last_modified = 0; |
2380 nullfree(local_res->etag); | 2380 nullfree(local_res->etag); |
2381 local_res->etag = NULL; | 2381 local_res->etag = NULL; |
2382 nullfree(local_res->hash); | 2382 nullfree(local_res->hash); |
2383 local_res->hash = NULL; | 2383 local_res->hash = NULL; |
2391 } | 2391 } |
2392 | 2392 |
2393 res_conflict = TRUE; | 2393 res_conflict = TRUE; |
2394 } else { | 2394 } else { |
2395 if(local_res->link_target) { | 2395 if(local_res->link_target) { |
2396 printf( | 2396 log_printf( |
2397 "link: %s -> %s\n", | 2397 "link: %s -> %s\n", |
2398 local_res->path, | 2398 local_res->path, |
2399 local_res->link_target); | 2399 local_res->link_target); |
2400 } else { | 2400 } else { |
2401 printf("put: %s\n", local_res->path); | 2401 log_printf("put: %s\n", local_res->path); |
2402 } | 2402 } |
2403 if(sync_put_resource(dir, res, local_res, &sync_success)) { | 2403 if(sync_put_resource(dir, res, local_res, &sync_success)) { |
2404 sync_error++; | 2404 sync_error++; |
2405 print_resource_error(sn, res->path); | 2405 print_resource_error(sn, res->path); |
2406 ret = -1; | 2406 ret = -1; |
2432 break; | 2432 break; |
2433 } | 2433 } |
2434 | 2434 |
2435 DavResource *res = dav_resource_new(sn, local_res->path); | 2435 DavResource *res = dav_resource_new(sn, local_res->path); |
2436 if(local_res->metadata_updated) { | 2436 if(local_res->metadata_updated) { |
2437 printf("update: %s\n", local_res->path); | 2437 log_printf("update: %s\n", local_res->path); |
2438 if(!sync_update_metadata(dir, sn, res, local_res)) { | 2438 if(!sync_update_metadata(dir, sn, res, local_res)) { |
2439 LocalResource *dbres = cxMapGet(db->resources, cx_hash_key_str(local_res->path)); | 2439 LocalResource *dbres = cxMapGet(db->resources, cx_hash_key_str(local_res->path)); |
2440 cxMapPut(db->resources, cx_hash_key_str(local_res->path), local_res); | 2440 cxMapPut(db->resources, cx_hash_key_str(local_res->path), local_res); |
2441 } | 2441 } |
2442 } | 2442 } |
2507 char *str_success = sync_success == 1 ? "file" : "files"; | 2507 char *str_success = sync_success == 1 ? "file" : "files"; |
2508 char *str_delete = sync_delete == 1 ? "file" : "files"; | 2508 char *str_delete = sync_delete == 1 ? "file" : "files"; |
2509 char *str_conflict = sync_conflict == 1 ? "conflict" : "conflicts"; | 2509 char *str_conflict = sync_conflict == 1 ? "conflict" : "conflicts"; |
2510 char *str_error = sync_error == 1 ? "error" : "errors"; | 2510 char *str_error = sync_error == 1 ? "error" : "errors"; |
2511 | 2511 |
2512 printf("Result: %d %s pushed, ", sync_success, str_success); | 2512 log_printf("Result: %d %s pushed, ", sync_success, str_success); |
2513 if(!archive) { | 2513 if(!archive) { |
2514 printf("%d %s deleted, ", sync_delete, str_delete); | 2514 log_printf("%d %s deleted, ", sync_delete, str_delete); |
2515 } | 2515 } |
2516 printf("%d %s, %d %s\n", | 2516 log_printf("%d %s, %d %s\n", |
2517 sync_conflict, str_conflict, sync_error, str_error); | 2517 sync_conflict, str_conflict, sync_error, str_error); |
2518 } | 2518 } |
2519 | 2519 |
2520 return ret; | 2520 return ret; |
2521 } | 2521 } |
2668 fprintf(stderr, "Abort\n"); | 2668 fprintf(stderr, "Abort\n"); |
2669 return -1; | 2669 return -1; |
2670 } | 2670 } |
2671 DavLock *lock = dav_get_lock(sn, "/"); | 2671 DavLock *lock = dav_get_lock(sn, "/"); |
2672 if(lock) { | 2672 if(lock) { |
2673 printf("Lock-Token: %s\n", lock->token); | 2673 log_printf("Lock-Token: %s\n", lock->token); |
2674 } | 2674 } |
2675 locked = TRUE; | 2675 locked = TRUE; |
2676 locktokenfile = create_locktoken_file(dir->name, lock->token); | 2676 locktokenfile = create_locktoken_file(dir->name, lock->token); |
2677 } | 2677 } |
2678 | 2678 |
2687 CxIterator iter = cxListIterator(modified); | 2687 CxIterator iter = cxListIterator(modified); |
2688 for(int i=0;i<2;i++) { | 2688 for(int i=0;i<2;i++) { |
2689 cx_foreach(LocalResource *, resource, iter) { | 2689 cx_foreach(LocalResource *, resource, iter) { |
2690 DavResource *res = dav_get(sn, resource->path, "D:getetag,idav:status,idav:version-collection,idav:split,`idav:content-hash`,idavprops:tags,idavprops:finfo,idavprops:xattributes,idavprops:link"); | 2690 DavResource *res = dav_get(sn, resource->path, "D:getetag,idav:status,idav:version-collection,idav:split,`idav:content-hash`,idavprops:tags,idavprops:finfo,idavprops:xattributes,idavprops:link"); |
2691 if(!res) { | 2691 if(!res) { |
2692 printf("skip: %s\n", resource->path); | 2692 log_printf("skip: %s\n", resource->path); |
2693 continue; | 2693 continue; |
2694 } | 2694 } |
2695 char *status = dav_get_string_property(res, "idav:status"); | 2695 char *status = dav_get_string_property(res, "idav:status"); |
2696 if(status && !strcmp(status, "broken")) { | 2696 if(status && !strcmp(status, "broken")) { |
2697 fprintf(stderr, "Resource %s broken\n", res->path); | 2697 fprintf(stderr, "Resource %s broken\n", res->path); |
2774 | 2774 |
2775 // Report | 2775 // Report |
2776 if(ret != -2) { | 2776 if(ret != -2) { |
2777 char *str_success = sync_success == 1 ? "file" : "files"; | 2777 char *str_success = sync_success == 1 ? "file" : "files"; |
2778 char *str_error = sync_error == 1 ? "error" : "errors"; | 2778 char *str_error = sync_error == 1 ? "error" : "errors"; |
2779 printf("Result: %d %s pulled, %d %s\n", | 2779 log_printf("Result: %d %s pulled, %d %s\n", |
2780 sync_success, str_success, | 2780 sync_success, str_success, |
2781 sync_error, str_error); | 2781 sync_error, str_error); |
2782 } | 2782 } |
2783 | 2783 |
2784 return ret; | 2784 return ret; |
2785 } | 2785 } |
2786 | 2786 |
2787 static void print_outgoging_file(LocalResource *res) { | 2787 static void print_outgoging_file(LocalResource *res) { |
2788 char *lastmodified = util_date_str(res->last_modified); | 2788 char *lastmodified = util_date_str(res->last_modified); |
2789 char *size = util_size_str(FALSE, res->size); | 2789 char *size = util_size_str(FALSE, res->size); |
2790 printf(" %-49s %12s %10s\n", res->path+1, lastmodified, size); | 2790 log_printf(" %-49s %12s %10s\n", res->path+1, lastmodified, size); |
2791 free(lastmodified); | 2791 free(lastmodified); |
2792 free(size); | 2792 free(size); |
2793 } | 2793 } |
2794 | 2794 |
2795 void print_outgoing( | 2795 void print_outgoing( |
2814 size_t len_cpy = ls_copy->size; | 2814 size_t len_cpy = ls_copy->size; |
2815 size_t len_mkc = ls_mkcol->size; | 2815 size_t len_mkc = ls_mkcol->size; |
2816 | 2816 |
2817 size_t total = len_new + len_mod + len_cnf + len_upd + len_del + len_mov + len_cpy + len_mkc; | 2817 size_t total = len_new + len_mod + len_cnf + len_upd + len_del + len_mov + len_cpy + len_mkc; |
2818 if(total == 0) { | 2818 if(total == 0) { |
2819 printf("no changes\n"); | 2819 log_printf("no changes\n"); |
2820 return; | 2820 return; |
2821 } | 2821 } |
2822 | 2822 |
2823 printf("%s\n", "File Last Modified Size"); | 2823 log_printf("%s\n", "File Last Modified Size"); |
2824 printf("%s\n", "=============================================================================="); | 2824 log_printf("%s\n", "=============================================================================="); |
2825 | 2825 |
2826 if(ls_mkcol) { | 2826 if(ls_mkcol) { |
2827 printf("Directories:\n"); | 2827 log_printf("Directories:\n"); |
2828 CxIterator i = cxListIterator(ls_mkcol); | 2828 CxIterator i = cxListIterator(ls_mkcol); |
2829 cx_foreach(LocalResource *, res, i) { | 2829 cx_foreach(LocalResource *, res, i) { |
2830 printf(" %-49s\n", res->path+1); | 2830 log_printf(" %-49s\n", res->path+1); |
2831 total_size += res->size; | 2831 total_size += res->size; |
2832 } | 2832 } |
2833 } | 2833 } |
2834 if(ls_new) { | 2834 if(ls_new) { |
2835 printf("New:\n"); | 2835 log_printf("New:\n"); |
2836 CxIterator i = cxListIterator(ls_new); | 2836 CxIterator i = cxListIterator(ls_new); |
2837 cx_foreach(LocalResource *, res, i) { | 2837 cx_foreach(LocalResource *, res, i) { |
2838 print_outgoging_file(res); | 2838 print_outgoging_file(res); |
2839 total_size += res->size; | 2839 total_size += res->size; |
2840 } | 2840 } |
2841 } | 2841 } |
2842 if(ls_modified) { | 2842 if(ls_modified) { |
2843 printf("Modified:\n"); | 2843 log_printf("Modified:\n"); |
2844 CxIterator i = cxListIterator(ls_modified); | 2844 CxIterator i = cxListIterator(ls_modified); |
2845 cx_foreach(LocalResource *, res, i) { | 2845 cx_foreach(LocalResource *, res, i) { |
2846 print_outgoging_file(res); | 2846 print_outgoging_file(res); |
2847 total_size += res->size; | 2847 total_size += res->size; |
2848 } | 2848 } |
2849 } | 2849 } |
2850 if(ls_update) { | 2850 if(ls_update) { |
2851 printf("Update:\n"); | 2851 log_printf("Update:\n"); |
2852 CxIterator i = cxListIterator(ls_update); | 2852 CxIterator i = cxListIterator(ls_update); |
2853 cx_foreach(LocalResource *, res, i) { | 2853 cx_foreach(LocalResource *, res, i) { |
2854 char *lastmodified = util_date_str(res->last_modified); | 2854 char *lastmodified = util_date_str(res->last_modified); |
2855 printf(" %-49s %12s\n", res->path+1, lastmodified); | 2855 log_printf(" %-49s %12s\n", res->path+1, lastmodified); |
2856 free(lastmodified); | 2856 free(lastmodified); |
2857 } | 2857 } |
2858 } | 2858 } |
2859 if(ls_delete) { | 2859 if(ls_delete) { |
2860 printf("Delete:\n"); | 2860 log_printf("Delete:\n"); |
2861 CxIterator i = cxListIterator(ls_delete); | 2861 CxIterator i = cxListIterator(ls_delete); |
2862 cx_foreach(LocalResource *, res, i) { | 2862 cx_foreach(LocalResource *, res, i) { |
2863 printf(" %s\n", res->path+1); | 2863 log_printf(" %s\n", res->path+1); |
2864 } | 2864 } |
2865 } | 2865 } |
2866 if(ls_copy) { | 2866 if(ls_copy) { |
2867 printf("Copy:\n"); | 2867 log_printf("Copy:\n"); |
2868 CxIterator i = cxListIterator(ls_copy); | 2868 CxIterator i = cxListIterator(ls_copy); |
2869 cx_foreach(LocalResource *, res, i) { | 2869 cx_foreach(LocalResource *, res, i) { |
2870 printf("%s -> %s\n", res->origin->path+1, res->path); | 2870 log_printf("%s -> %s\n", res->origin->path+1, res->path); |
2871 } | 2871 } |
2872 } | 2872 } |
2873 if(ls_move) { | 2873 if(ls_move) { |
2874 printf("Move:\n"); | 2874 log_printf("Move:\n"); |
2875 CxIterator i = cxListIterator(ls_move); | 2875 CxIterator i = cxListIterator(ls_move); |
2876 cx_foreach(LocalResource *, res, i) { | 2876 cx_foreach(LocalResource *, res, i) { |
2877 printf("%s -> %s\n", res->origin->path+1, res->path); | 2877 log_printf("%s -> %s\n", res->origin->path+1, res->path); |
2878 } | 2878 } |
2879 } | 2879 } |
2880 if(ls_conflict) { | 2880 if(ls_conflict) { |
2881 printf("Conflict\n"); | 2881 log_printf("Conflict\n"); |
2882 CxIterator i = cxListIterator(ls_conflict); | 2882 CxIterator i = cxListIterator(ls_conflict); |
2883 cx_foreach(LocalResource *, res, i) { | 2883 cx_foreach(LocalResource *, res, i) { |
2884 printf(" %s\n", res->path+1); | 2884 log_printf(" %s\n", res->path+1); |
2885 } | 2885 } |
2886 } | 2886 } |
2887 | 2887 |
2888 char *total_size_str = util_size_str(FALSE, total_size); | 2888 char *total_size_str = util_size_str(FALSE, total_size); |
2889 | 2889 |
2890 printf("\n"); | 2890 log_printf("\n"); |
2891 if(len_new > 0) printf("new: %zu, ", len_new); | 2891 if(len_new > 0) log_printf("new: %zu, ", len_new); |
2892 if(len_mod > 0) printf("modified: %zu, ", len_mod); | 2892 if(len_mod > 0) log_printf("modified: %zu, ", len_mod); |
2893 if(len_upd > 0) printf("updated: %zu, ", len_upd); | 2893 if(len_upd > 0) log_printf("updated: %zu, ", len_upd); |
2894 if(len_cpy > 0) printf("copied: %zu, ", len_cpy); | 2894 if(len_cpy > 0) log_printf("copied: %zu, ", len_cpy); |
2895 if(len_mov > 0) printf("moved: %zu, ", len_mov); | 2895 if(len_mov > 0) log_printf("moved: %zu, ", len_mov); |
2896 if(len_del > 0) printf("deleted: %zu, ", len_del); | 2896 if(len_del > 0) log_printf("deleted: %zu, ", len_del); |
2897 if(len_cnf > 0) printf("conflicts: %zu, ", len_cnf); | 2897 if(len_cnf > 0) log_printf("conflicts: %zu, ", len_cnf); |
2898 printf("total size: %s\n", total_size_str); | 2898 log_printf("total size: %s\n", total_size_str); |
2899 | 2899 |
2900 free(total_size_str); | 2900 free(total_size_str); |
2901 } | 2901 } |
2902 | 2902 |
2903 CxList* local_scan(SyncDirectory *dir, SyncDatabase *db) { | 2903 CxList* local_scan(SyncDirectory *dir, SyncDatabase *db) { |
4503 if(res->iscollection) { | 4503 if(res->iscollection) { |
4504 DavXmlNode *split = dav_get_property_ns(res, DAV_NS, "split"); | 4504 DavXmlNode *split = dav_get_property_ns(res, DAV_NS, "split"); |
4505 if(cols) { | 4505 if(cols) { |
4506 cxListAdd(cols, local_res); | 4506 cxListAdd(cols, local_res); |
4507 } else if(split || !res->children) { | 4507 } else if(split || !res->children) { |
4508 printf("delete: %s\n", res->path); | 4508 log_printf("delete: %s\n", res->path); |
4509 if(dav_delete(res)) { | 4509 if(dav_delete(res)) { |
4510 ret = 1; | 4510 ret = 1; |
4511 fprintf(stderr, "Cannot delete collection %s\n", res->path); | 4511 fprintf(stderr, "Cannot delete collection %s\n", res->path); |
4512 } else { | 4512 } else { |
4513 (*counter)++; | 4513 (*counter)++; |
4522 } | 4522 } |
4523 | 4523 |
4524 if(!nullstrcmp(etag, local_res->etag)) { | 4524 if(!nullstrcmp(etag, local_res->etag)) { |
4525 // local resource metadata == remote resource metadata | 4525 // local resource metadata == remote resource metadata |
4526 // resource can be deleted | 4526 // resource can be deleted |
4527 printf("delete: %s\n", res->path); | 4527 log_printf("delete: %s\n", res->path); |
4528 int exists = 1; | 4528 int exists = 1; |
4529 int vend_required = 0; | 4529 int vend_required = 0; |
4530 if(dir->versioning && dir->versioning->always) { | 4530 if(dir->versioning && dir->versioning->always) { |
4531 if(versioning_delete_begin(dir, res, &exists, &vend_required)) { | 4531 if(versioning_delete_begin(dir, res, &exists, &vend_required)) { |
4532 fprintf( | 4532 fprintf( |
4784 destroy_db(db); | 4784 destroy_db(db); |
4785 | 4785 |
4786 // Report | 4786 // Report |
4787 if(ret != -2) { | 4787 if(ret != -2) { |
4788 char *str_conflict = num_conflict == 1 ? "conflict" : "conflicts"; | 4788 char *str_conflict = num_conflict == 1 ? "conflict" : "conflicts"; |
4789 printf("Result: %d %s resolved\n", num_conflict, str_conflict); | 4789 log_printf("Result: %d %s resolved\n", num_conflict, str_conflict); |
4790 } | 4790 } |
4791 | 4791 |
4792 return ret; | 4792 return ret; |
4793 } | 4793 } |
4794 | 4794 |
4821 int ret = 0; | 4821 int ret = 0; |
4822 | 4822 |
4823 // delete all conflict files | 4823 // delete all conflict files |
4824 CxIterator i = cxMapIteratorValues(db->conflict); | 4824 CxIterator i = cxMapIteratorValues(db->conflict); |
4825 cx_foreach(LocalResource*, res, i) { | 4825 cx_foreach(LocalResource*, res, i) { |
4826 printf("delete: %s\n", res->path); | 4826 log_printf("delete: %s\n", res->path); |
4827 char *path = create_local_path(dir, res->path); | 4827 char *path = create_local_path(dir, res->path); |
4828 if(sys_unlink(path)) { | 4828 if(sys_unlink(path)) { |
4829 if(errno != ENOENT) { | 4829 if(errno != ENOENT) { |
4830 perror("unlink"); | 4830 perror("unlink"); |
4831 num_err++; | 4831 num_err++; |
4850 | 4850 |
4851 // Report | 4851 // Report |
4852 if(ret == 0) { | 4852 if(ret == 0) { |
4853 char *str_delete = num_del == 1 ? "file" : "files"; | 4853 char *str_delete = num_del == 1 ? "file" : "files"; |
4854 char *str_error = num_err == 1 ? "error" : "errors"; | 4854 char *str_error = num_err == 1 ? "error" : "errors"; |
4855 printf("Result: %d conflict %s deleted, %d %s\n", | 4855 log_printf("Result: %d conflict %s deleted, %d %s\n", |
4856 num_del, str_delete, | 4856 num_del, str_delete, |
4857 num_err, str_error); | 4857 num_err, str_error); |
4858 } | 4858 } |
4859 | 4859 |
4860 return ret; | 4860 return ret; |
4896 cxListSort(conflict_sources); | 4896 cxListSort(conflict_sources); |
4897 i = cxListIterator(conflict_sources); | 4897 i = cxListIterator(conflict_sources); |
4898 char *prev = ""; | 4898 char *prev = ""; |
4899 cx_foreach(char *, path, i) { | 4899 cx_foreach(char *, path, i) { |
4900 // TODO: implement verbose print if(cmd_getoption(a, "verbose")) | 4900 // TODO: implement verbose print if(cmd_getoption(a, "verbose")) |
4901 // printf("%s (%d)\n", path, confl_count); | 4901 // log_printf("%s (%d)\n", path, confl_count); |
4902 if(!strcmp(path, prev)) { | 4902 if(!strcmp(path, prev)) { |
4903 continue; | 4903 continue; |
4904 } | 4904 } |
4905 | 4905 |
4906 printf("%s\n", path); | 4906 log_printf("%s\n", path); |
4907 | 4907 |
4908 prev = path; | 4908 prev = path; |
4909 } | 4909 } |
4910 | 4910 |
4911 // cleanup | 4911 // cleanup |
4986 struct tm *date = gmtime(&now); | 4986 struct tm *date = gmtime(&now); |
4987 char str[32]; | 4987 char str[32]; |
4988 putenv("LC_TIME=C"); | 4988 putenv("LC_TIME=C"); |
4989 size_t len = strftime(str, 32, "%a, %d %b %Y %H:%M:%S GMT", date); | 4989 size_t len = strftime(str, 32, "%a, %d %b %Y %H:%M:%S GMT", date); |
4990 | 4990 |
4991 printf("name: %s\n", name); | 4991 log_printf("name: %s\n", name); |
4992 printf("lastmodified: %s\n", str); | 4992 log_printf("lastmodified: %s\n", str); |
4993 char *server = util_url_base(res->session->base_url); | 4993 char *server = util_url_base(res->session->base_url); |
4994 char *url = util_concat_path(server, res->href); | 4994 char *url = util_concat_path(server, res->href); |
4995 printf("url: %s\n", url); | 4995 log_printf("url: %s\n", url); |
4996 free(server); | 4996 free(server); |
4997 free(url); | 4997 free(url); |
4998 } | 4998 } |
4999 | 4999 |
5000 int cmd_list_versions(CmdArgs *a) { | 5000 int cmd_list_versions(CmdArgs *a) { |
5122 if(scfg_check_dir(syncdir)) { | 5122 if(scfg_check_dir(syncdir)) { |
5123 return -1; | 5123 return -1; |
5124 } | 5124 } |
5125 | 5125 |
5126 if(!syncdir->trash) { | 5126 if(!syncdir->trash) { |
5127 printf("trash not configured for %s\n", syncdir->name); | 5127 log_printf("trash not configured for %s\n", syncdir->name); |
5128 return 0; | 5128 return 0; |
5129 } | 5129 } |
5130 | 5130 |
5131 SYS_DIR dir = sys_opendir(syncdir->trash); | 5131 SYS_DIR dir = sys_opendir(syncdir->trash); |
5132 if(!dir) { | 5132 if(!dir) { |
5155 | 5155 |
5156 free(path); | 5156 free(path); |
5157 } | 5157 } |
5158 sys_closedir(dir); | 5158 sys_closedir(dir); |
5159 | 5159 |
5160 printf("path: %s\n", syncdir->trash); | 5160 log_printf("path: %s\n", syncdir->trash); |
5161 printf("%d %s\n", count, count == 1 ? "file" : "files"); | 5161 log_printf("%d %s\n", count, count == 1 ? "file" : "files"); |
5162 char *sizestr = size_str(trashsize); | 5162 char *sizestr = size_str(trashsize); |
5163 printf("%s\n", sizestr); | 5163 log_printf("%s\n", sizestr); |
5164 free(sizestr); | 5164 free(sizestr); |
5165 | 5165 |
5166 return 0; | 5166 return 0; |
5167 } | 5167 } |
5168 | 5168 |
5196 if(!strcmp(ent->name, ".") || !strcmp(ent->name, "..")) { | 5196 if(!strcmp(ent->name, ".") || !strcmp(ent->name, "..")) { |
5197 continue; | 5197 continue; |
5198 } | 5198 } |
5199 | 5199 |
5200 char *path = util_concat_path(syncdir->trash, ent->name); | 5200 char *path = util_concat_path(syncdir->trash, ent->name); |
5201 printf("delete: %s\n", path); | 5201 log_printf("delete: %s\n", path); |
5202 | 5202 |
5203 SYS_STAT s; | 5203 SYS_STAT s; |
5204 if(sys_stat(path, &s)) { | 5204 if(sys_stat(path, &s)) { |
5205 perror("stat"); | 5205 perror("stat"); |
5206 free(path); | 5206 free(path); |
5298 tags = sync_get_file_tags(file.dir, localres, NULL, NULL); | 5298 tags = sync_get_file_tags(file.dir, localres, NULL, NULL); |
5299 CxIterator i = cxListIterator(tags ? tags : cxEmptyList); | 5299 CxIterator i = cxListIterator(tags ? tags : cxEmptyList); |
5300 int x = -1; | 5300 int x = -1; |
5301 cx_foreach(DavTag *, t, i) { | 5301 cx_foreach(DavTag *, t, i) { |
5302 if(cmd == CMD_TAG_LIST) { | 5302 if(cmd == CMD_TAG_LIST) { |
5303 printf("%s\n", t->name); | 5303 log_printf("%s\n", t->name); |
5304 } else if(!strcmp(t->name, tag)) { | 5304 } else if(!strcmp(t->name, tag)) { |
5305 x = i.index; | 5305 x = i.index; |
5306 break; | 5306 break; |
5307 } | 5307 } |
5308 } | 5308 } |
5500 | 5500 |
5501 // TODO: port to ucx 3 | 5501 // TODO: port to ucx 3 |
5502 return 1; | 5502 return 1; |
5503 #if 0 | 5503 #if 0 |
5504 | 5504 |
5505 printf("Each sync directory must have an unique name.\n"); | 5505 log_printf("Each sync directory must have an unique name.\n"); |
5506 char *name = assistant_getcfg("name"); | 5506 char *name = assistant_getcfg("name"); |
5507 if(!name) { | 5507 if(!name) { |
5508 fprintf(stderr, "Abort\n"); | 5508 fprintf(stderr, "Abort\n"); |
5509 return -1; | 5509 return -1; |
5510 } | 5510 } |
5511 if(scfg_get_dir(name)) { | 5511 if(scfg_get_dir(name)) { |
5512 fprintf(stderr, "Directory %s already exists.\nAbort\n", name); | 5512 fprintf(stderr, "Directory %s already exists.\nAbort\n", name); |
5513 return -1; | 5513 return -1; |
5514 } | 5514 } |
5515 | 5515 |
5516 printf("Enter local directory path.\n"); | 5516 log_printf("Enter local directory path.\n"); |
5517 char *path = assistant_getcfg("path"); | 5517 char *path = assistant_getcfg("path"); |
5518 if(!path) { | 5518 if(!path) { |
5519 fprintf(stderr, "Abort\n"); | 5519 fprintf(stderr, "Abort\n"); |
5520 return -1; | 5520 return -1; |
5521 } | 5521 } |
5522 | 5522 |
5523 printf("Specify webdav repository.\n"); | 5523 log_printf("Specify webdav repository.\n"); |
5524 CxIterator repos = get_repositories(); | 5524 CxIterator repos = get_repositories(); |
5525 int i = 0; | 5525 int i = 0; |
5526 cx_foreach(Repository *, r, repos) { | 5526 cx_foreach(Repository *, r, repos) { |
5527 printf("%d) %s\n", i, r->name); | 5527 log_printf("%d) %s\n", i, r->name); |
5528 i++; | 5528 i++; |
5529 } | 5529 } |
5530 char *repository = assistant_getcfg("repository"); | 5530 char *repository = assistant_getcfg("repository"); |
5531 char *reponame = NULL; | 5531 char *reponame = NULL; |
5532 if(!repository) { | 5532 if(!repository) { |
5554 fprintf(stderr, "Repository %s doesn't exist.\nAbort\n", repository); | 5554 fprintf(stderr, "Repository %s doesn't exist.\nAbort\n", repository); |
5555 return -1; | 5555 return -1; |
5556 } | 5556 } |
5557 } | 5557 } |
5558 | 5558 |
5559 printf("Enter collection relative to the repository base url.\n"); | 5559 log_printf("Enter collection relative to the repository base url.\n"); |
5560 char *collection = assistant_getdefcfg("collection", "/"); | 5560 char *collection = assistant_getdefcfg("collection", "/"); |
5561 | 5561 |
5562 char *db = generate_db_name(name); | 5562 char *db = generate_db_name(name); |
5563 | 5563 |
5564 SyncDirectory dir; | 5564 SyncDirectory dir; |
5573 int ret = 0; | 5573 int ret = 0; |
5574 if(add_directory(&dir)) { | 5574 if(add_directory(&dir)) { |
5575 fprintf(stderr, "Cannot write sync.xml\n"); | 5575 fprintf(stderr, "Cannot write sync.xml\n"); |
5576 ret = -1; | 5576 ret = -1; |
5577 } else { | 5577 } else { |
5578 printf("\nAdded directory: %s (%s)\n", name, path); | 5578 log_printf("\nAdded directory: %s (%s)\n", name, path); |
5579 } | 5579 } |
5580 | 5580 |
5581 free(name); | 5581 free(name); |
5582 free(path); | 5582 free(path); |
5583 free(repository); | 5583 free(repository); |
5589 } | 5589 } |
5590 | 5590 |
5591 int cmd_list_dirs() { | 5591 int cmd_list_dirs() { |
5592 CxIterator iter = scfg_directory_iterator(); | 5592 CxIterator iter = scfg_directory_iterator(); |
5593 cx_foreach(SyncDirectory *, dir, iter) { | 5593 cx_foreach(SyncDirectory *, dir, iter) { |
5594 printf("%s\n", dir->name); | 5594 log_printf("%s\n", dir->name); |
5595 } | 5595 } |
5596 return 0; | 5596 return 0; |
5597 } | 5597 } |
5598 | 5598 |
5599 int cmd_check_repositories(CmdArgs *a) { | 5599 int cmd_check_repositories(CmdArgs *a) { |
5607 } | 5607 } |
5608 } | 5608 } |
5609 | 5609 |
5610 CxIterator iter = cxListIterator(reponames); | 5610 CxIterator iter = cxListIterator(reponames); |
5611 cx_foreach(char *, reponame, iter) { | 5611 cx_foreach(char *, reponame, iter) { |
5612 printf("Checking %s... ", reponame); | 5612 log_printf("Checking %s... ", reponame); |
5613 Repository* repo = get_repository(cx_str(reponame)); | 5613 Repository* repo = get_repository(cx_str(reponame)); |
5614 if (!repo) { | 5614 if (!repo) { |
5615 printf(" not found in config.xml!\n"); | 5615 log_printf(" not found in config.xml!\n"); |
5616 ret = EXIT_FAILURE; | 5616 ret = EXIT_FAILURE; |
5617 } else { | 5617 } else { |
5618 DavSession *sn = create_session(a, ctx, repo, repo->url); | 5618 DavSession *sn = create_session(a, ctx, repo, repo->url); |
5619 if (sn) { | 5619 if (sn) { |
5620 DavResource *res = dav_query(sn, | 5620 DavResource *res = dav_query(sn, |
5621 "select - from / with depth = 0"); | 5621 "select - from / with depth = 0"); |
5622 if (res) { | 5622 if (res) { |
5623 printf("OK.\n"); | 5623 log_printf("OK.\n"); |
5624 dav_resource_free(res); | 5624 dav_resource_free(res); |
5625 } else { | 5625 } else { |
5626 printf("unavailable!\n"); | 5626 log_printf("unavailable!\n"); |
5627 ret = EXIT_FAILURE; | 5627 ret = EXIT_FAILURE; |
5628 } | 5628 } |
5629 dav_session_destroy(sn); | 5629 dav_session_destroy(sn); |
5630 } else { | 5630 } else { |
5631 printf("cannot create session!\n"); | 5631 log_printf("cannot create session!\n"); |
5632 ret = EXIT_FAILURE; | 5632 ret = EXIT_FAILURE; |
5633 } | 5633 } |
5634 } | 5634 } |
5635 } | 5635 } |
5636 | 5636 |