dav/sync.c

changeset 723
5ca174b3247a
parent 702
444aa8fe133f
child 724
9c2f0072abed
equal deleted inserted replaced
722:d78619cc5a4d 723:5ca174b3247a
203 ret = EXIT_FAILURE; 203 ret = EXIT_FAILURE;
204 } 204 }
205 } else if(!cfgret) { 205 } else if(!cfgret) {
206 if(!strcmp(cmd, "pull")) { 206 if(!strcmp(cmd, "pull")) {
207 tid = start_sighandler(&mutex); 207 tid = start_sighandler(&mutex);
208 ret = cmd_pull(args); 208 ret = cmd_pull(args, FALSE);
209 stop_sighandler(&mutex, tid); 209 stop_sighandler(&mutex, tid);
210 } else if(!strcmp(cmd, "push")) { 210 } else if(!strcmp(cmd, "push")) {
211 tid = start_sighandler(&mutex); 211 tid = start_sighandler(&mutex);
212 ret = cmd_push(args, FALSE); 212 ret = cmd_push(args, FALSE, FALSE);
213 stop_sighandler(&mutex, tid); 213 stop_sighandler(&mutex, tid);
214 } else if(!strcmp(cmd, "outgoing")) {
215 ret = cmd_push(args, TRUE, FALSE);
214 } else if(!strcmp(cmd, "archive")) { 216 } else if(!strcmp(cmd, "archive")) {
215 tid = start_sighandler(&mutex); 217 tid = start_sighandler(&mutex);
216 ret = cmd_push(args, TRUE); 218 ret = cmd_push(args, FALSE, TRUE);
217 stop_sighandler(&mutex, tid); 219 stop_sighandler(&mutex, tid);
218 } else if(!strcmp(cmd, "restore")) { 220 } else if(!strcmp(cmd, "restore")) {
219 tid = start_sighandler(&mutex); 221 tid = start_sighandler(&mutex);
220 ret = cmd_restore(args); 222 ret = cmd_restore(args);
221 stop_sighandler(&mutex, tid); 223 stop_sighandler(&mutex, tid);
544 res = res->next; 546 res = res->next;
545 } 547 }
546 } 548 }
547 } 549 }
548 550
549 int cmd_pull(CmdArgs *a) { 551 int cmd_pull(CmdArgs *a, DavBool incoming) {
550 if(a->argc != 1) { 552 if(a->argc != 1) {
551 fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few" : "many"); 553 fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few" : "many");
552 return -1; 554 return -1;
553 } 555 }
554 // if there are syntax errors in the command line, fail asap. 556 // if there are syntax errors in the command line, fail asap.
1878 1880
1879 static int res_isconflict(SyncDatabase *db, LocalResource *res) { 1881 static int res_isconflict(SyncDatabase *db, LocalResource *res) {
1880 return ucx_map_cstr_get(db->conflict, res->path) ? 1 : 0; 1882 return ucx_map_cstr_get(db->conflict, res->path) ? 1 : 0;
1881 } 1883 }
1882 1884
1883 int cmd_push(CmdArgs *a, DavBool archive) { 1885 int cmd_push(CmdArgs *a, DavBool outgoing, DavBool archive) {
1884 if(a->argc != 1) { 1886 if(a->argc != 1) {
1885 fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few" : "many"); 1887 fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few" : "many");
1886 return -1; 1888 return -1;
1887 } 1889 }
1888 1890
1963 int cdt = cmd_getoption(a, "conflict") ? 0 : 1; // conflict detection 1965 int cdt = cmd_getoption(a, "conflict") ? 0 : 1; // conflict detection
1964 1966
1965 // lock repository 1967 // lock repository
1966 DavBool locked = FALSE; 1968 DavBool locked = FALSE;
1967 char *locktokenfile = NULL; 1969 char *locktokenfile = NULL;
1968 if((dir->lockpush || cmd_getoption(a, "lock")) && !cmd_getoption(a, "nolock")) { 1970 if((dir->lockpush || cmd_getoption(a, "lock")) && !cmd_getoption(a, "nolock") && !outgoing) {
1969 if(dav_lock_t(root, dir->lock_timeout)) { 1971 if(dav_lock_t(root, dir->lock_timeout)) {
1970 print_resource_error(sn, "/"); 1972 print_resource_error(sn, "/");
1971 dav_session_destroy(sn); 1973 dav_session_destroy(sn);
1972 fprintf(stderr, "Abort\n"); 1974 fprintf(stderr, "Abort\n");
1973 return -1; 1975 return -1;
1998 UcxList *ls_update = NULL; 2000 UcxList *ls_update = NULL;
1999 UcxList *ls_delete = NULL; 2001 UcxList *ls_delete = NULL;
2000 UcxList *ls_move = NULL; 2002 UcxList *ls_move = NULL;
2001 UcxList *ls_copy = NULL; 2003 UcxList *ls_copy = NULL;
2002 UcxList *ls_mkcol = NULL; 2004 UcxList *ls_mkcol = NULL;
2003 2005
2004 // upload all changed files 2006 // upload all changed files
2005 //UcxList *resources = cmd_getoption(a, "read") ? 2007 //UcxList *resources = cmd_getoption(a, "read") ?
2006 // read_changes(dir, db) : local_scan(dir, db); 2008 // read_changes(dir, db) : local_scan(dir, db);
2007 UcxList *resources = local_scan(dir, db); 2009 UcxList *resources = local_scan(dir, db);
2008 UcxMap *resources_map = ucx_map_new(ucx_list_size(resources)+16); 2010 UcxMap *resources_map = ucx_map_new(ucx_list_size(resources)+16);
2152 } 2154 }
2153 } 2155 }
2154 UCX_FOREACH(elm, removed_res) { 2156 UCX_FOREACH(elm, removed_res) {
2155 LocalResource *local = elm->data; 2157 LocalResource *local = elm->data;
2156 ucx_map_cstr_remove(db->resources, local->path); 2158 ucx_map_cstr_remove(db->resources, local->path);
2159 }
2160
2161 if(outgoing) {
2162 print_outgoing(
2163 ls_new,
2164 ls_modified,
2165 ls_conflict,
2166 ls_update,
2167 ls_delete,
2168 ls_move,
2169 ls_copy,
2170 ls_mkcol);
2171 return 0;
2157 } 2172 }
2158 2173
2159 // 2174 //
2160 // BEGIN PUSH 2175 // BEGIN PUSH
2161 // 2176 //
2696 } 2711 }
2697 2712
2698 return ret; 2713 return ret;
2699 } 2714 }
2700 2715
2716 static void print_outgoging_file(LocalResource *res) {
2717 char *lastmodified = util_date_str(res->last_modified);
2718 char *size = util_size_str(FALSE, res->size);
2719 printf(" %-49s %12s %10s\n", res->path+1, lastmodified, size);
2720 free(lastmodified);
2721 free(size);
2722 }
2723
2724 void print_outgoing(
2725 UcxList *ls_new,
2726 UcxList *ls_modified,
2727 UcxList *ls_conflict,
2728 UcxList *ls_update,
2729 UcxList *ls_delete,
2730 UcxList *ls_move,
2731 UcxList *ls_copy,
2732 UcxList *ls_mkcol)
2733 {
2734 printf("%s\n", "File Last Modified Size");
2735 printf("%s\n", "==============================================================================");
2736
2737 int num_files = 0;
2738 int64_t total_size = 0;
2739
2740 if(ls_mkcol) {
2741 printf("Directories:\n");
2742 UCX_FOREACH(elm, ls_mkcol) {
2743 LocalResource *res = elm->data;
2744 printf(" %-49s\n", res->path+1);
2745 total_size += res->size;
2746 num_files++;
2747 }
2748 }
2749 if(ls_new) {
2750 printf("New:\n");
2751 UCX_FOREACH(elm, ls_new) {
2752 LocalResource *res = elm->data;
2753 print_outgoging_file(elm->data);
2754 total_size += res->size;
2755 num_files++;
2756 }
2757 }
2758 if(ls_modified) {
2759 printf("Modified:\n");
2760 UCX_FOREACH(elm, ls_modified) {
2761 LocalResource *res = elm->data;
2762 print_outgoging_file(elm->data);
2763 total_size += res->size;
2764 num_files++;
2765 }
2766 }
2767 if(ls_update) {
2768 printf("Update:\n");
2769 UCX_FOREACH(elm, ls_update) {
2770 LocalResource *res = elm->data;
2771 char *lastmodified = util_date_str(res->last_modified);
2772 printf(" %-49s %12s\n", res->path+1, lastmodified);
2773 free(lastmodified);
2774 num_files++;
2775 }
2776 }
2777 if(ls_delete) {
2778 printf("Delete:\n");
2779 UCX_FOREACH(elm, ls_delete) {
2780 LocalResource *res = elm->data;
2781 printf(" %s\n", res->path+1);
2782 }
2783 }
2784 if(ls_copy) {
2785 printf("Copy:\n");
2786 UCX_FOREACH(elm, ls_copy) {
2787 LocalResource *res = elm->data;
2788 printf("%s -> %s\n", res->origin->path+1, res->path);
2789 num_files++;
2790 }
2791 }
2792 if(ls_move) {
2793 printf("Move:\n");
2794 UCX_FOREACH(elm, ls_move) {
2795 LocalResource *res = elm->data;
2796 printf("%s -> %s\n", res->origin->path+1, res->path);
2797 num_files++;
2798 }
2799 }
2800 if(ls_conflict) {
2801 printf("Conflict\n");
2802 UCX_FOREACH(elm, ls_conflict) {
2803 LocalResource *res = elm->data;
2804 printf(" %s\n", res->path+1);
2805 }
2806 }
2807
2808 char *total_size_str = util_size_str(FALSE, total_size);
2809 printf("\n%d outgoing files, size: %s\n", num_files, total_size_str);
2810 free(total_size_str);
2811 }
2812
2701 UcxList* local_scan(SyncDirectory *dir, SyncDatabase *db) { 2813 UcxList* local_scan(SyncDirectory *dir, SyncDatabase *db) {
2702 UcxList *resources = NULL; 2814 UcxList *resources = NULL;
2703 2815
2704 char *path = strdup("/"); 2816 char *path = strdup("/");
2705 UcxList *stack = ucx_list_prepend(NULL, path); 2817 UcxList *stack = ucx_list_prepend(NULL, path);

mercurial