dav/main.c

changeset 355
5da2cf15eb44
parent 354
067ea2315a8a
child 361
b6f2462ee055
equal deleted inserted replaced
354:067ea2315a8a 355:5da2cf15eb44
372 dav_session_set_authcallback(sn, request_auth2, repo); 372 dav_session_set_authcallback(sn, request_auth2, repo);
373 } 373 }
374 return sn; 374 return sn;
375 } 375 }
376 376
377 int update_progress(DavResource *res, int64_t total, int64_t now, Progress *p) {
378 int ret = 0;
379 if(res != p->last_resource) {
380 p->cur += p->last_res_total - p->last_res_cur;
381 ret = 1;
382 } else {
383 p->cur += now - p->last_res_cur;
384 }
385
386 p->last_resource = res;
387 p->last_res_cur = now;
388 p->last_res_total = total;
389
390 return ret;
391 }
392
393 void download_progress(DavResource *res, int64_t total, int64_t now, void *data) {
394 Progress *p = data;
395 int newres = update_progress(res, total, now, p);
396
397 time_t newts = time(NULL);
398 if(newres || (p->ts != newts)) {
399 fprintf(p->out, "[%s]: %" PRId64 "k/%" PRId64 "k total: %" PRId64 "M/%" PRId64 "M\n", res->name, now/1024, total/1024, p->cur/(1024*1024), p->total/(1024*1024));
400 fflush(p->out);
401 }
402 p->ts = newts;
403 }
404
405
377 #define LIST_QUERY_ORDER_BY_NAME "select `idav:crypto-name`,`idav:crypto-key`,D:lockdiscovery,apache:executable from %s with depth = %d where lastmodified > %t order by iscollection desc, name" 406 #define LIST_QUERY_ORDER_BY_NAME "select `idav:crypto-name`,`idav:crypto-key`,D:lockdiscovery,apache:executable from %s with depth = %d where lastmodified > %t order by iscollection desc, name"
378 #define LIST_QUERY_ORDER_BY_DATE "select `idav:crypto-name`,`idav:crypto-key`,D:lockdiscovery,apache:executable from %s with depth = %d where lastmodified > %t order by iscollection desc, lastmodified desc" 407 #define LIST_QUERY_ORDER_BY_DATE "select `idav:crypto-name`,`idav:crypto-key`,D:lockdiscovery,apache:executable from %s with depth = %d where lastmodified > %t order by iscollection desc, lastmodified desc"
379 408
380 int cmd_list(CmdArgs *a) { 409 int cmd_list(CmdArgs *a) {
381 if(a->argc != 1) { 410 if(a->argc != 1) {
654 683
655 if(set_session_config(sn, a)) { 684 if(set_session_config(sn, a)) {
656 return -1; 685 return -1;
657 } 686 }
658 687
688 char *progressfile = cmd_getoption(a, "progressfile");
689 Progress pdata;
690 memset(&pdata, 0, sizeof(Progress));
691 if(progressfile) {
692 if(!strcmp(progressfile, "-")) {
693 pdata.out = stdout;
694 pdata.isstdout = 1;
695 } else {
696 pdata.out = fopen(progressfile, "w");
697 }
698 if(pdata.out) {
699 dav_session_set_progresscallback(sn, download_progress, NULL, &pdata);
700 }
701 }
702
659 char *update = cmd_getoption(a, "update"); 703 char *update = cmd_getoption(a, "update");
660 time_t t = -1; 704 time_t t = -1;
661 if(update) { 705 if(update) {
662 t = util_parse_lastmodified(update); 706 t = util_parse_lastmodified(update);
663 if (t == 0) { 707 if (t == 0) {
762 reslist = ucx_list_append(reslist, g); 806 reslist = ucx_list_append(reslist, g);
763 } 807 }
764 } 808 }
765 809
766 // download resources 810 // download resources
811 pdata.total = totalsize;
812
767 int ret; 813 int ret;
768 getfunc get; 814 getfunc get;
769 TarOutputStream *tout = NULL; 815 TarOutputStream *tout = NULL;
770 if(tar) { 816 if(tar) {
771 get = (getfunc)resource2tar; 817 get = (getfunc)resource2tar;
796 842
797 ucx_list_free_content(reslist, free_getres); 843 ucx_list_free_content(reslist, free_getres);
798 ucx_list_free(reslist); 844 ucx_list_free(reslist);
799 free(path); 845 free(path);
800 846
847 if(pdata.out && !pdata.isstdout) {
848 fclose(pdata.out);
849 }
801 return ret; 850 return ret;
802 } 851 }
803 852
804 int get_resource(Repository *repo, GetResource *getres, CmdArgs *a, void *unused) { 853 int get_resource(Repository *repo, GetResource *getres, CmdArgs *a, void *unused) {
805 DavResource *res = getres->res; 854 DavResource *res = getres->res;

mercurial