diff options
author | Ryo Nakamura <upa@haeena.net> | 2023-09-13 14:35:44 +0900 |
---|---|---|
committer | Ryo Nakamura <upa@haeena.net> | 2023-11-01 19:54:18 +0900 |
commit | 139ba12f1a7c35a572d33991f4c3960f61490dfe (patch) | |
tree | 67b1b88c5bb1119e7d8d1f54b36f1ef8cf29ff0a | |
parent | cfbadebe6dfeb148d687df3bc91448674054cb82 (diff) |
write total transferred bytes and number of files
at the end of output when serverity is notice.
-rw-r--r-- | src/main.c | 63 | ||||
-rw-r--r-- | src/mscp.c | 14 |
2 files changed, 46 insertions, 31 deletions
@@ -536,17 +536,42 @@ struct xfer_stat { }; struct xfer_stat x; -void print_stat_thread_cleanup(void *arg) +void print_stat(bool final) { + struct pollfd pfd = { .fd = msg_fd, .events = POLLIN }; struct mscp_stats s; + char buf[8192]; + int timeout; + + if (poll(&pfd, 1, !final ? 100 : 0) < 0) { + fprintf(stderr, "poll: %s\n", strerror(errno)); + return; + } + + if (pfd.revents & POLLIN) { + memset(buf, 0, sizeof(buf)); + if (read(msg_fd, buf, sizeof(buf)) < 0) { + fprintf(stderr, "read: %s\n", strerror(errno)); + return; + } + print_cli("\r\033[K" "%s", buf); + } gettimeofday(&x.after, NULL); - mscp_get_stats(m, &s); - x.total = s.total; - x.done = s.done; + if (calculate_timedelta(&x.before, &x.after) > 1 || final) { + mscp_get_stats(m, &s); + x.total = s.total; + x.done = s.done; + print_progress(!final ? &x.before : &x.start, &x.after, + x.total, !final ? x.last : 0, x.done, final); + x.before = x.after; + x.last = x.done; + } +} - /* print progress from the beginning */ - print_progress(&x.start, &x.after, x.total, 0, x.done, true); +void print_stat_thread_cleanup(void *arg) +{ + print_stat(true); print_cli("\n"); /* final output */ } @@ -565,31 +590,7 @@ void *print_stat_thread(void *arg) pthread_cleanup_push(print_stat_thread_cleanup, NULL); while (true) { - if (poll(&pfd, 1, 100) < 0) { - fprintf(stderr, "poll: %s\n", strerror(errno)); - return NULL; - } - - if (pfd.revents & POLLIN) { - memset(buf, 0, sizeof(buf)); - if (read(msg_fd, buf, sizeof(buf)) < 0) { - fprintf(stderr, "read: %s\n", strerror(errno)); - return NULL; - } - print_cli("\r\033[K" "%s", buf); - } - - gettimeofday(&x.after, NULL); - if (calculate_timedelta(&x.before, &x.after) > 1) { - mscp_get_stats(m, &s); - x.total = s.total; - x.done = s.done; - - print_progress(&x.before, &x.after, x.total, x.last, x.done, - false); - x.before = x.after; - x.last = x.done; - } + print_stat(false); } pthread_cleanup_pop(1); @@ -554,6 +554,8 @@ int mscp_start(struct mscp *m) int mscp_join(struct mscp *m) { struct mscp_thread *t; + struct path *p; + size_t done = 0, nr_copied = 0, nr_tobe_copied = 0; int n, ret = 0; /* waiting for scan thread joins... */ @@ -563,6 +565,7 @@ int mscp_join(struct mscp *m) RWLOCK_READ_ACQUIRE(&m->thread_rwlock); list_for_each_entry(t, &m->thread_list, list) { pthread_join(t->tid, NULL); + done += t->done; if (t->ret < 0) ret = t->ret; if (t->sftp) { @@ -577,6 +580,17 @@ int mscp_join(struct mscp *m) m->first = NULL; } + /* count up number of transferred files */ + list_for_each_entry(p, &m->path_list, list) { + nr_tobe_copied++; + if (p->state == FILE_STATE_DONE) { + nr_copied++; + } + } + + mpr_notice(m->msg_fp, "%lu/%lu bytes copied for %lu/%lu files\n", + done, m->total_bytes, nr_copied, nr_tobe_copied); + return ret; } |