diff -r 067ea2315a8a -r 5da2cf15eb44 dav/main.c --- a/dav/main.c Mon Dec 18 11:56:11 2017 +0100 +++ b/dav/main.c Mon Dec 18 16:24:32 2017 +0100 @@ -374,6 +374,35 @@ return sn; } +int update_progress(DavResource *res, int64_t total, int64_t now, Progress *p) { + int ret = 0; + if(res != p->last_resource) { + p->cur += p->last_res_total - p->last_res_cur; + ret = 1; + } else { + p->cur += now - p->last_res_cur; + } + + p->last_resource = res; + p->last_res_cur = now; + p->last_res_total = total; + + return ret; +} + +void download_progress(DavResource *res, int64_t total, int64_t now, void *data) { + Progress *p = data; + int newres = update_progress(res, total, now, p); + + time_t newts = time(NULL); + if(newres || (p->ts != newts)) { + 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)); + fflush(p->out); + } + p->ts = newts; +} + + #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" #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" @@ -656,6 +685,21 @@ return -1; } + char *progressfile = cmd_getoption(a, "progressfile"); + Progress pdata; + memset(&pdata, 0, sizeof(Progress)); + if(progressfile) { + if(!strcmp(progressfile, "-")) { + pdata.out = stdout; + pdata.isstdout = 1; + } else { + pdata.out = fopen(progressfile, "w"); + } + if(pdata.out) { + dav_session_set_progresscallback(sn, download_progress, NULL, &pdata); + } + } + char *update = cmd_getoption(a, "update"); time_t t = -1; if(update) { @@ -764,6 +808,8 @@ } // download resources + pdata.total = totalsize; + int ret; getfunc get; TarOutputStream *tout = NULL; @@ -798,6 +844,9 @@ ucx_list_free(reslist); free(path); + if(pdata.out && !pdata.isstdout) { + fclose(pdata.out); + } return ret; }