dav/main.c

changeset 30
9a5a7a513a96
parent 29
938957a4eea7
child 31
59cdf7b7316f
equal deleted inserted replaced
29:938957a4eea7 30:9a5a7a513a96
99 } 99 }
100 100
101 void print_usage(char *cmd) { 101 void print_usage(char *cmd) {
102 fprintf(stderr, "Usage: %s command [options] arguments...\n\n", cmd); 102 fprintf(stderr, "Usage: %s command [options] arguments...\n\n", cmd);
103 fprintf(stderr, "Commands:\n"); 103 fprintf(stderr, "Commands:\n");
104 fprintf(stderr, " list [-altR] <url>\n"); 104 fprintf(stderr, "list [-altR] [-u <date>] <url>\n");
105 fprintf(stderr, " get [-pR] [-k <key>] [-o <file>] <url>\n"); 105 fprintf(
106 stderr,
107 " get [-pR] [-k <key>] [-o <file>] [-u <date>] <url>\n");
106 fprintf(stderr, " put [-p] [-k <key>] <url> <file>\n"); 108 fprintf(stderr, " put [-p] [-k <key>] <url> <file>\n");
107 fprintf(stderr, " mkdir <url>\n"); 109 fprintf(stderr, " mkdir <url>\n");
108 fprintf(stderr, " remove <url>\n"); 110 fprintf(stderr, " remove <url>\n");
109 fprintf(stderr, " date [url]\n"); 111 fprintf(stderr, " date [url]\n");
110 fprintf(stderr, "\n"); 112 fprintf(stderr, "\n");
114 fprintf(stderr, " -p Don't encrypt or decrypt files\n"); 116 fprintf(stderr, " -p Don't encrypt or decrypt files\n");
115 fprintf(stderr, 117 fprintf(stderr,
116 " -R " 118 " -R "
117 "Recursively do the operation for all children\n"); 119 "Recursively do the operation for all children\n");
118 fprintf(stderr, " -o <file> Write output to file\n"); 120 fprintf(stderr, " -o <file> Write output to file\n");
121 fprintf(
122 stderr,
123 " -u <date> "
124 "Get resources which are modified since the specified date\n");
119 fprintf(stderr, " -a show all files\n"); 125 fprintf(stderr, " -a show all files\n");
120 fprintf(stderr, " -l print resources in long list format\n"); 126 fprintf(stderr, " -l print resources in long list format\n");
121 fprintf(stderr, " -t print content type\n"); 127 fprintf(stderr, " -t print content type\n");
122 fprintf(stderr, "\n"); 128 fprintf(stderr, "\n");
123 fprintf(stderr, 129 fprintf(stderr,
212 } else { 218 } else {
213 base = util_concat_path(root, path); 219 base = util_concat_path(root, path);
214 sn = dav_session_new(ctx, base); 220 sn = dav_session_new(ctx, base);
215 } 221 }
216 222
223 char *update = cmd_getoption(a, "update");
224 time_t t = 0;
225 if(update) {
226 t = util_parse_lastmodified(update);
227 }
228
217 DavResource *ls; 229 DavResource *ls;
218 if(cmd_getoption(a, "recursive")) { 230 if(cmd_getoption(a, "recursive")) {
219 printf("base: %s\n", base); 231 printf("base: %s\n", base);
220 ls = dav_query(sn, "get U:crypto-key from /*"); 232 if(update) {
221 } else { 233 ls = dav_query(
222 ls = dav_query(sn, "get U:crypto-key from /"); 234 sn,
235 "get U:crypto-key from /* where lastmodified > %t",
236 t);
237 } else {
238 ls = dav_query(sn, "get U:crypto-key from /*");
239 }
240 } else {
241 if(update) {
242 ls = dav_query(
243 sn,
244 "get U:crypto-key from / where lastmodified > %t", t);
245 } else {
246 ls = dav_query(sn, "get U:crypto-key from /");
247 }
223 } 248 }
224 if(!ls) { 249 if(!ls) {
225 print_resource_error(sn, path); 250 print_resource_error(sn, path);
226 free(root); 251 free(root);
227 free(path); 252 free(path);
416 sn = dav_session_new_auth(ctx, repo->url, repo->user, repo->password); 441 sn = dav_session_new_auth(ctx, repo->url, repo->user, repo->password);
417 } else { 442 } else {
418 sn = dav_session_new(ctx, root); 443 sn = dav_session_new(ctx, root);
419 } 444 }
420 445
446 char *update = cmd_getoption(a, "update");
447 time_t t = 0;
448 if(update) {
449 t = util_parse_lastmodified(update);
450 }
451
421 int recursive = cmd_getoption(a, "recursive") ? 1 : 0; 452 int recursive = cmd_getoption(a, "recursive") ? 1 : 0;
422 DavResource *res; 453 DavResource *res;
454
423 if(recursive) { 455 if(recursive) {
424 res = dav_query(sn, "get U:crypto-key from %s*", path); 456 if(update) {
425 } else { 457 res = dav_query(
426 res = dav_query(sn, "get U:crypto-key from %s", path); 458 sn,
459 "get U:crypto-key from %s* where lastmodified > %t",
460 path,
461 t);
462 } else {
463 res = dav_query(sn, "get U:crypto-key from %s*", path);
464 }
465 } else {
466 if(update) {
467 res = dav_query(
468 sn,
469 "get U:crypto-key from %s where lastmodified > %t",
470 path,
471 t);
472 } else {
473 res = dav_query(sn, "get U:crypto-key from %s", path);
474 }
427 } 475 }
428 if(!res) { 476 if(!res) {
429 print_resource_error(sn, path); 477 print_resource_error(sn, path);
430 return -1; 478 return -1;
431 } 479 }

mercurial