71 print_usage(argv[0]); |
71 print_usage(argv[0]); |
72 return -1; |
72 return -1; |
73 } |
73 } |
74 int ret = EXIT_FAILURE; |
74 int ret = EXIT_FAILURE; |
75 |
75 |
76 int loadcfg = 1; |
76 if(!strcasecmp(cmd, "version") || !strcasecmp(cmd, "-version") |
77 if(!strcasecmp(cmd, "version") || !strcasecmp(cmd, "-version") || !strcasecmp(cmd, "--version")) { |
77 || !strcasecmp(cmd, "--version")) { |
78 fprintf(stderr, "dav-sync %s\n", DAV_VERSION); |
78 fprintf(stderr, "dav-sync %s\n", DAV_VERSION); |
79 loadcfg = 0; |
|
80 cmd_args_free(args); |
79 cmd_args_free(args); |
81 return -1; |
80 return -1; |
82 } |
81 } |
83 |
82 |
84 if(loadcfg) { |
83 xmlGenericErrorFunc fnc = xmlerrorfnc; |
85 xmlGenericErrorFunc fnc = xmlerrorfnc; |
84 initGenericErrorDefaultFunc(&fnc); |
86 initGenericErrorDefaultFunc(&fnc); |
85 ctx = dav_context_new(); |
87 ctx = dav_context_new(); |
86 int cfgret = load_config(ctx) || load_sync_config(); |
88 load_config(ctx); |
87 |
89 |
88 if(!strcmp(cmd, "check") || !strcmp(cmd, "check-config")) { |
90 // copy proxy config |
89 if(!cfgret) { |
91 memcpy(ctx->http_proxy, get_http_proxy(), sizeof(Proxy)); |
90 fprintf(stdout, "Configuration OK.\n"); |
92 memcpy(ctx->https_proxy, get_https_proxy(), sizeof(Proxy)); |
91 ret = EXIT_SUCCESS; |
93 |
92 } else { |
94 if(load_sync_config()) { |
93 /* no output, the warnings are written by load_config */ |
95 cmd_args_free(args); |
94 ret = EXIT_FAILURE; |
96 dav_context_destroy(ctx); |
95 } |
97 return EXIT_FAILURE; |
96 } else if(!cfgret) { |
98 } |
97 if(!strcmp(cmd, "pull")) { |
99 } |
98 ret = cmd_pull(args); |
100 |
99 } else if(!strcmp(cmd, "push")) { |
101 if(!strcmp(cmd, "pull")) { |
100 ret = cmd_push(args); |
102 ret = cmd_pull(args); |
101 } else if(!strcmp(cmd, "resolve-conflicts")) { |
103 } else if(!strcmp(cmd, "push")) { |
102 ret = cmd_resolve_conflicts(args); |
104 ret = cmd_push(args); |
103 } else if(!strcmp(cmd, "delete-conflicts")) { |
105 } else if(!strcmp(cmd, "resolve-conflicts")) { |
104 ret = cmd_delete_conflicts(args); |
106 ret = cmd_resolve_conflicts(args); |
105 } else if(!strcmp(cmd, "trash-info")) { |
107 } else if(!strcmp(cmd, "delete-conflicts")) { |
106 ret = cmd_trash_info(args); |
108 ret = cmd_delete_conflicts(args); |
107 } else if(!strcmp(cmd, "empty-trash")) { |
109 } else if(!strcmp(cmd, "trash-info")) { |
108 ret = cmd_empty_trash(args); |
110 ret = cmd_trash_info(args); |
109 } else if(!strcmp(cmd, "add-directory")) { |
111 } else if(!strcmp(cmd, "empty-trash")) { |
110 ret = cmd_add_directory(args); |
112 ret = cmd_empty_trash(args); |
111 } else if(!strcmp(cmd, "list-directories")) { |
113 } else if(!strcmp(cmd, "add-directory")) { |
112 ret = list_syncdirs(); |
114 ret = cmd_add_directory(args); |
113 } else if(!strcmp(cmd, "check-repositories")) { |
115 } else if(!strcmp(cmd, "list-directories")) { |
114 ret = cmd_check_repositories(); |
116 ret = list_syncdirs(); |
115 } else { |
117 } else { |
116 print_usage(argv[0]); |
118 print_usage(argv[0]); |
117 } |
119 } |
118 } |
120 |
119 |
121 // cleanup |
120 // cleanup |
122 cmd_args_free(args); |
121 cmd_args_free(args); |
123 dav_context_destroy(ctx); |
122 dav_context_destroy(ctx); |
149 //fprintf(stderr, " -r Read changes from stdin\n\n"); |
148 //fprintf(stderr, " -r Read changes from stdin\n\n"); |
150 fprintf(stderr, " -v verbose output (all commands)\n\n"); |
149 fprintf(stderr, " -v verbose output (all commands)\n\n"); |
151 |
150 |
152 fprintf(stderr, "Config commands:\n"); |
151 fprintf(stderr, "Config commands:\n"); |
153 fprintf(stderr, " add-directory\n"); |
152 fprintf(stderr, " add-directory\n"); |
154 fprintf(stderr, " list-directories\n\n"); |
153 fprintf(stderr, " list-directories\n"); |
|
154 fprintf(stderr, " check (or check-config)\n"); |
|
155 fprintf(stderr, " check-repositories\n\n"); |
155 } |
156 } |
156 |
157 |
157 static int res_matches_filter(SyncDirectory *dir, char *res_path) { |
158 static int res_matches_filter(SyncDirectory *dir, char *res_path) { |
158 // trash filter |
159 // trash filter |
159 if (dir->trash) { |
160 if (dir->trash) { |